Yes, that is a good piece of code to know.  Thank you, I will be using that
in the future!


-- 
Noah Sussman
Senior Web Developer
Deltathree, The IP Communications Network
75 Broad St, 31st Floor
New York, NY 10004
tel 212-500-4845
fax 212-500-4888
[EMAIL PROTECTED]
www.deltathree.com


"Nature will tell you a direct lie if she can."

    -Charles Darwin


> From: "Jos I Boumans" <[EMAIL PROTECTED]>
> Date: Tue, 15 May 2001 22:46:39 +0200
> To: "Noah Sussman" <[EMAIL PROTECTED]>, "Peter Cornelius"
> <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]>
> Subject: Re: negative matching?
> 
> a handy bit of code to use for that is the following:
> 
> { local $/; $in=<FILEHANDLE> }
> 
> that undefs $/, which is the line seperator in perl (defaults to \n), which
> means perl knows no longer a way to split lines,
> and will feed everything in FILEHANDLE to $in.
> 
> local and the { } means that $/ original value will be restored once the
> block exits...
> 
> this basicly has the same effect as saying:
> 
> while(<FILEHANDLE>) { $in .= $_; }
> 
> except that the local $/ solution is a bit more elegant and efficient =)
> 
> Regards,
> 
> Jos Boumans
> 
> 
> ----- Original Message -----
> From: "Noah Sussman" <[EMAIL PROTECTED]>
> To: "Noah Sussman" <[EMAIL PROTECTED]>; "Peter Cornelius"
> <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> Sent: Tuesday, May 15, 2001 10:14 PM
> Subject: Re: negative matching?
> 
> 
>> oops, I just said that:
>> 
>>> Also, the regex I originally included will place alt attributes in _all_
> IMG
>>> tags, even if they already contain an alt attribute.
>> 
>> Actually, the unless() stops that behavior, but creates a new problem in
>> that, once it finds and IMG tag that has an ALT attribute, it stops the
>> search altogether.
>> 
>> I just wanted to clarify, since the problem is now solved. (See Jeff
>> Pinyan's contribution to this thread for the solution.)
>> 
>> Thanks again!
>> 
>> 
>> --
>> Noah Sussman
>> Senior Web Developer
>> Deltathree, The IP Communications Network
>> 75 Broad St, 31st Floor
>> New York, NY 10004
>> tel 212-500-4845
>> fax 212-500-4888
>> [EMAIL PROTECTED]
>> www.deltathree.com
>> 
>> 
>> "The first 90% of the code accounts for the first 90% of the development
>> time. The remaining 10% of the code accounts for the other 90% of the
>> development time."
>> 
>> -Tom Cargill
>> 
>>> From: Noah Sussman <[EMAIL PROTECTED]>
>>> Date: Tue, 15 May 2001 16:05:39 -0400
>>> To: Peter Cornelius <[EMAIL PROTECTED]>,
> <[EMAIL PROTECTED]>
>>> Subject: Re: negative matching?
>>> 
>>>> Why do you
>>>> want to slurp everything into $_ at once?
>>> 
>>> Because I want to insert the alt attribute even if the IMG tag spans
> several
>>> newlines, as is often the case once one's code has been mangled by the
>>> server.
>>> 
>>> Also, the regex I originally included will place alt attributes in _all_
> IMG
>>> tags, even if they already contain an alt attribute.
>>> 
>>> 
>>> 
>>> 
>>> --
>>> Noah Sussman
>>> Senior Web Developer
>>> Deltathree, The IP Communications Network
>>> 75 Broad St, 31st Floor
>>> New York, NY 10004
>>> tel 212-500-4845
>>> fax 212-500-4888
>>> [EMAIL PROTECTED]
>>> www.deltathree.com
>>> 
>>> 
>>> "There is nothing more deceptive than an obvious fact."
>>> 
>>> -Sherlock Holmes
>>> 
>>> 
>>>> From: Peter Cornelius <[EMAIL PROTECTED]>
>>>> Date: Mon, 14 May 2001 16:51:29 -0700
>>>> To: 'Noah Sussman' <[EMAIL PROTECTED]>, [EMAIL PROTECTED]
>>>> Subject: RE: negative matching?
>>>> 
>>>> This seems to work for me as log as I leave out the 'undef $/;'  Why do
> you
>>>> want to slurp everything into $_ at once?
>>>> 
>>>> -----Original Message-----
>>>> From: Noah Sussman [mailto:[EMAIL PROTECTED]]
>>>> Sent: Monday, May 14, 2001 4:29 PM
>>>> To: [EMAIL PROTECTED]
>>>> Subject: negative matching?
>>>> 
>>>> 
>>>> I am trying to write a simple script to insert ALT attributes into IMG
> tags
>>>> that don't have them, leaving other IMG tags untouched.
>>>> 
>>>> The problem is that I can't figure out how to tell Perl to search for
>>>> strings beginning with "<IMG", ending with ">" AND not containing
> "ALT="
>>>> (and it has to do this over multiple lines as well!).
>>>> 
>>>> This is my code so far, any comments would be hugely appreciated:
>>>> 
>>>> #! -w
>>>> use strict;
>>>> 
>>>> undef $/;
>>>> 
>>>> my $text = "hello" ;
>>>> 
>>>> while (<>) {
>>>> 
>>>> unless (m{<img.*?alt=.*?>}ix){
>>>> 
>>>> s{(<img)(.*?)>}{$1$2 alt="$text">}gsix;
>>>> 
>>>> }
>>>> 
>>>> print "$_";
>>>> 
>>>> }
>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> --
>>>> Noah Sussman
>>>> Senior Web Developer
>>>> Deltathree, The IP Communications Network
>>>> 75 Broad St, 31st Floor
>>>> New York, NY 10004
>>>> tel 212-500-4845
>>>> fax 212-500-4888
>>>> [EMAIL PROTECTED]
>>>> www.deltathree.com
>>>> 
>>>> 
>>>> "Nature will tell you a direct lie if she can."
>>>> 
>>>> -Charles Darwin
>>>> 
>>> 
>> 
>> 
> 

Reply via email to