in reply to command line pipe

You seem to be confused about the difference between command-line arguments and piping. If you say ls *.txt | ./myscript.pl, the STDOUT output of ls is going to STDIN of your script. Yet you are trying to get the names of those .txt files from @ARGV.

To actually get the filenames from the piped input, do something like:

chomp( my @filenames = <STDIN> ); for (@filenames) { ... # open, read, etc }
A better solution for your particular example, though, is Zaxo's advice above. Use the -n option, or use the magic while (<>) loop: both automatically use the members of @ARGV as filenames and open them in sequence for you, reducing the code you've written to a one-liner.

Alternately, look at xargs to do something like this:

$ ls *.txt | xargs ./myscript.pl
.. which takes the name of each txt file (as given by ls) and passes it as a command-line argument (i.e, an element of @ARGV) to myscript.pl (plus or minus quoting/escaping issues)

blokhead

Replies are listed 'Best First'.
Re: Re: command line pipe
by pengyou_ah (Initiate) on Jul 23, 2003 at 06:25 UTC
    Thanks for the help everyone. The reason I didn't use the oneliner is that I need to open
    the files for further processing. 'Blokhead's solution is ultimately what I needed.
    You're right, I was confused about pipes and args but I've got it working now.