View Single Post
  #1 (permalink)  
Old 06-10-2007, 05:31 PM
Magician
Posts: n/a
[SOLVED] Using $ARGV[1] in PERL to open any text file for this program.?

How can I use $ARGV[1] in replace of 'data.txt' or something like $ARGV[1] in this code:

# PRO1.pl
open (MYFILE, 'data.txt');
while (<MYFILE>) {
chomp;
print "$_\n";
}
close (MYFILE);

so that I can run any text file in this program.

For example

$ perl PRO1.pl part1.txt
$ perl PRO1.pl part2.txt
$ perl PRO1.pl part3.txt

Do I have to change this code completely, or can I do something like replace 'data.txt' with '$ARGV[1]'.

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!