read a file from the command line in perl
July 27th, 2006 by Lawrence David
to read in a file and print its contents (filename specified as the first command-line argument):
my($my_file) = $ARGV[0];
open(MYFILE,$my_file);while ()
{
print $_;
}
July 27th, 2006 by Lawrence David
to read in a file and print its contents (filename specified as the first command-line argument):
my($my_file) = $ARGV[0];
open(MYFILE,$my_file);while ()
{
print $_;
}
Or you could use:
perl -e “while(){print;}” myfile.txt
Or even just:
perl -pe “” myfile.txt
Or, for the true minimalist:
perl -p myfile.txt