searching for multiple instances of many strings in Perl
Posted: Wed Dec 30, 2009 5:47 pm
I am writing a tiny perl script using LWP to download webpages which have multiple links in it,
each one having a certain value, such as
many instances of this name in the page and many different names. What I am hoping to
do is to count all instances of "Pleb sauce", "horsehair underpants" etc.
I found this script on a webpage which looks like it might do what I want:
But the problem is the while loop; is there a better way to run a script without having to
run through this loop for each regex?
Thanks!
Paul
each one having a certain value, such as
, so that I can extract, in this case "pleb sauce". However, there are<a href="http://www.poobar.com">pleb sauce</a>
many instances of this name in the page and many different names. What I am hoping to
do is to count all instances of "Pleb sauce", "horsehair underpants" etc.
I found this script on a webpage which looks like it might do what I want:
Code: Select all
#!/usr/bin/perl
use strict;
my $string = "CATINTHEHATWITHABAT"; // just a test
my $regex = '\wAT'; // This needs to be replaced with an array containing
// all the regexs; in this case, could be '\wHA', '\wTH', etc.
my @matches = ();
while ($string =~ /($regex)/gi){
// do stuff here, increment counter etc.
}
run through this loop for each regex?
Thanks!
Paul