[Chicago-talk] Q on '-n'
walter at torres.ws
Tue Sep 16 02:14:39 CDT 2003
I'm trying to figure out how to utilize '-n' best.
I have a cmd line...
myScript.pl file_1.txt file_2.txt -o result.out
I want to cycle through all file[s] given by the cmd line (if it's a path,
all the files in that dir, but that's for later) and spit the results
(whatever it may be) into the file given via the '-o' parameter.
My test script (see below)
Is this the best way to accomplish this?
Thanks for your help.
# place entire cmd line into single scalar
$arg = join ' ', @ARGV;
# split off the inbound file(s) and the result file
($arg, $outFile) = split '-o', $arg;
# rebuilt the cmd line
@ARGV = split ' ', $arg;
# Open given tmp file
open( TEMP, ">>$outFile")
or die "No Way! \n$!\n$outFile\n";
# loop begins here
print TEMP "$ARGV: $.\n";
# clode the file when we are done with it
close ARGV if eof;
More information about the Chicago-talk