in reply to File and Word as Command Line arguments, Output # of Occurences
my $file = $ARGV[0];
It's far more common to specify non-file arguments first, i.e. to call the script like
script.pl word file1 file2...
with possibly many files listed (cf. grep). Perl makes this approach easy with the diamond operator:
my $word = shift; while (<>) { # Reads the files line by line, # ... $ARGV contains the filename. }
You can use eof to reset the count if you want to output the count by file.
my declares a variable. It's unrelated to the task; it's possible to write the script without using it (which doesn't mean it's a good idea).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: File and Word as Command Line arguments, Output # of Occurences
by Specerion (Initiate) on Oct 28, 2015 at 00:35 UTC | |
by choroba (Cardinal) on Oct 28, 2015 at 00:52 UTC |