H
havel.zhang
dear perl-gurus,
i don't understand how this function works. can you please give me
further
explanation:
the program is very simple:
+++++++++++++program++++++++++++++++++++++
open (O,"<z.html");
@l = <O>;
close(O);
foreach(@l){
if ($_ =~ /<a\b([^>]+)(.*?)<\/a>/ig){
$html=$_;
while($html =~ m{a\b([^>]+)(.*?)</a>}ig){
my $Guts = $1;
my $Link = $2;
print "$Guts\n$Link\n";
}
}
};
++++++++z.html content+++++++++++++++++++++
the z.html 's content is:
<A HREF="http://10.123.111.11">link1</A><A HREF="text.txt">text.txt</
A><A HREF=
"fes.iso">fes.iso</A>
+++++++and output is:++++++++++++++++++++++++++++
HREF="http://10.123.111.11"
I want to using this program pick out hrefs and lables like
"link1","text.txt","fes.iso".
This program works well, but i can't understand the while loop with
regex:
"$html =~ m{a\b([^>]+)(.*?)</a>}ig"
^^^^^^^^^^^^^^^^^^^^^^^
it's works fine, and so amazing everytime, it's pick out patten "<a
href=...></a>" and get right result. But HOW does it work? I think it
will always pick out the first matched patten.
Can any perl guru give me answer?
Thank you
Havel
i don't understand how this function works. can you please give me
further
explanation:
the program is very simple:
+++++++++++++program++++++++++++++++++++++
open (O,"<z.html");
@l = <O>;
close(O);
foreach(@l){
if ($_ =~ /<a\b([^>]+)(.*?)<\/a>/ig){
$html=$_;
while($html =~ m{a\b([^>]+)(.*?)</a>}ig){
my $Guts = $1;
my $Link = $2;
print "$Guts\n$Link\n";
}
}
};
++++++++z.html content+++++++++++++++++++++
the z.html 's content is:
<A HREF="http://10.123.111.11">link1</A><A HREF="text.txt">text.txt</
A><A HREF=
"fes.iso">fes.iso</A>
+++++++and output is:++++++++++++++++++++++++++++
HREF="http://10.123.111.11"
++++++++end+++++++++++++++++++++++++++++++++link1 HREF="text.txt"
HREF="fes.iso"
fes.iso
I want to using this program pick out hrefs and lables like
"link1","text.txt","fes.iso".
This program works well, but i can't understand the while loop with
regex:
"$html =~ m{a\b([^>]+)(.*?)</a>}ig"
^^^^^^^^^^^^^^^^^^^^^^^
it's works fine, and so amazing everytime, it's pick out patten "<a
href=...></a>" and get right result. But HOW does it work? I think it
will always pick out the first matched patten.
Can any perl guru give me answer?
Thank you
Havel