Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
# The filename should be the first arguement $file = $ARGV[0]; # The search string should be the second arguement $searchString = $ARGV[1]; $matchesFound = 0; if (-e $file) { open (INPUTFILE, "<$file") or die "Can't open $file for input.\n"; while ($record = <INPUTFILE>) { $_ = $record; if (/$searchString/g) { print $record; $matchesFound = $matchesFound + 1; } } close INPUTFILE; print "$matchesFound found.\n"; } else { print "$file doesn't exist.\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Pattern Matching Confusion
by DrWhy (Chaplain) on Aug 11, 2005 at 13:49 UTC | |
|
Re: Pattern Matching Confusion
by bofh_of_oz (Hermit) on Aug 11, 2005 at 14:04 UTC | |
|
Re: Pattern Matching Confusion
by Codon (Friar) on Aug 11, 2005 at 17:03 UTC | |
|
Re: Pattern Matching Confusion
by kirbyk (Friar) on Aug 11, 2005 at 17:14 UTC | |
|
Re: Pattern Matching Confusion
by phaylon (Curate) on Aug 11, 2005 at 13:31 UTC | |
|
Re: Pattern Matching Confusion
by newroz (Monk) on Aug 11, 2005 at 14:09 UTC | |
by davido (Cardinal) on Aug 11, 2005 at 15:33 UTC |