stephanm has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
I have a little program file that's meant to search itself for lines which contain a specific word which is the first word in line 3 (ie $testVar).
For some reason it does not work.
Anyone clues as to how to make this work?
Thanks.### this file is called regex.pl my $testVar; $testVar = "January"; ### read this file open(FH,"<regex.pl") or die "cannot open file"; my @myself = <FH>; close(FH); ### make $pattern: $testVar $myself[2]=~/([^ ]+)/; my $pattern = $1; print "Pattern: $pattern\n"; ### print lines with this pattern for(@myself) { print if /$pattern/; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: regex search fails
by jethro (Monsignor) on Mar 12, 2009 at 14:39 UTC | |
by ikegami (Patriarch) on Mar 12, 2009 at 15:09 UTC | |
Re: regex search fails
by friedo (Prior) on Mar 12, 2009 at 14:41 UTC | |
by stephanm (Sexton) on Mar 12, 2009 at 23:03 UTC |
Back to
Seekers of Perl Wisdom