Feed on
Posts
Comments

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 $_;
}


Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

One Response to “read a file from the command line in perl”

  1. on 14 Nov 2006 at 1:33 pm Evil Overlord

    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

Did I get this wrong? Let me know!

Trackback URI | Comments RSS

More blogs about http://desk.stinkpot.org:8080/tricks.