[SOLVED] Multiple pattern matches on the same line in perl?
Posted: Sat Aug 07, 2004 3:56 pm
How do I serach for multiple pattern matches ANYWHERE in a file in perl? At the moment it stops reading and moves to the next line as soon as it finds a match. I need it to carry on along the line to see if there are anymore matches.
Here's my code (it looks for hyperlinks and extracts the url in html files.
I know I've got unused vars etc in there but it's just the beginning of a longer program. I always got the impression "g" would make the search global so is it something to do with my regexp? The regexp allows for spaces where html would forgive whitespace too. See if anyone can make this work for me 
Thanks
Here's my code (it looks for hyperlinks and extracts the url in html files.
Code: Select all
#!/perl/bin/perl -w
%args = ();
$i = 0;
foreach $filenames (@ARGV) {
$args{$i} = $filenames;
if (-e $filenames) {
open(DATA, "< $filenames");
while (<DATA>) {
if (m{<\s*a\s+href\s*=\s*"(ї^"]+)"\s*>}gi) {
print ("$1 is a link in file $filenames\n");
}
}
} else {
print ("\n\nFile: $filenames does not exist in this directory\n");
}
++$i;
}Thanks