I'm searching a text file for keywords. These keywords are stored in an array. First, I read the file into a scalar variable. Then, I search for each keyword, cycling through the array in an outer foreach loop: foreach $keyword (@keywords)
The keywords should be in all caps as a heading -- all by themselves on a line. I have noticed they can be either centered, or right or left justified.
I thought this would do the trick:
if($wholefile =~ /^\s*$keyword\s*$/)
Start and end of line: ^ and $ Zero or more whitespace on either side: \s* But it doesn't work. Won't pull up anything. I'm doing something dumb here.
This works, but is not as specific as I would like:
if($wholefile =~ m/$keyword/)
Any suggestions?
-- Craig
Use the /g modifier to do the looping and collect in an array?
Kinda like this, maybe:
my $slurp;
{open my $infile, '<', 'donor_query.pl' or die $!;
local $/=undef; $slurp = <$infile>;close $infile}my @keywords = qw/print pod $query/ ;
foreach (@keywords){
my $regex = qr/\Q$_\E/;my @matched = $slurp =~ /[^\w]$regex[^\w]/msgi; print $_, ': appears ', scalar @matched, ' times'; print "\n"; }
HTH,
-- mike higgins
_______________________________________________ ActivePerl mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
