At 8:37 pm +1000 5/9/02, Shannon Murdoch wrote:

>Unfortunately I'm not a command-line wiz <:(.  Could you explain how the
>target file/directory parameters are usually passed to the script when it IS
>called from the command line?

Suppose you have a perl script "test.pl" as below saved with UNIX 
line endings in your user directory, and in the same directory you 
have three text files "a.txt", "b.txt", "c.txt" ...

#!/usr/bin/perl
foreach $file (@ARGV){
   open FILE, $file;
   print <FILE>;
}


and at the command prompt you type:

cd;  perl test.pl a.text b.txt c.txt


then test.pl will loop through the array of path names -- @ARGV -- 
and print their contents to STDOUT -- the terminal.

The script can be abbreviated to just this:

    for (<>) {print}

In other words, the argument array is whatever follows the script 
name in the command line.

JD




Reply via email to