Craig Cardimon <[EMAIL PROTECTED]> wrote:
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?
Try (untested):
if($wholefile =~ /^\W*$keyword\W*$/)
If you don't have whitespace fore and aft then maybe you
have some other nonword character(s).
Regards,
Martin
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs