> 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