> -----Original Message-----
> From: Cohan, Drew [mailto:[EMAIL PROTECTED]]
> Sent: Friday, August 10, 2001 8:32 AM
> To: '[EMAIL PROTECTED]'
> Subject: confused over cookbook example 6-2
>
>
> I'm trying to modify cookbook example 6-2:
>
> #killtags: very bad html tag killer
> undef $/;
> while(<>){
> s/<.*?>//gs;
> print;
> }
>
> to instead look for all "href=" in an html file across
> paragraphs/newlines
> but I only get the first successful match. why does the
> cookbook's work but
> not mine?
>
> undef $/;
> while(<>){
> /href="(.*?)"/gs;
> print "$1\n";
> }
The cookbook is using s//, while you are using m//. The /g modifier on
s// will replace all ocurrences in the string. The /g modifer on m//
means that the matching starts where the last match left off. After
you find the first match and print it, your loop body ends and proceeds
to read from the next file in @ARGV (becuase $/ was undefined).
You need to execute the match repeatedly. This should work:
undef $/;
while(<>){
print "$1\n" while /href="(.*?)"/igs;
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]