in reply to Pattern matching against a variable
That will get a line of user input, loop over FILE and print if a given line matches $pat. Because regexes are interpolated the $ of $pat isn't interpreted as the meta-character $, but is interpolated into the regex match. See. perlop and perlre for more information on regexes and their quoting behaviour.## remove regex-unfriendly newline chomp( my $pat = <STDIN> ); open(FILE, "filename") or die("ack: $!"); while(<FILE>) { print if /$pat/; }
_________
broquaint
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Pattern matching against a variable
by bonoboy (Sexton) on Nov 04, 2003 at 11:19 UTC | |
by broquaint (Abbot) on Nov 04, 2003 at 11:25 UTC | |
by bonoboy (Sexton) on Nov 04, 2003 at 11:35 UTC |