Eric Lease Morgan wrote:


How do I get a Perl program to accept input from STDIN as well as command line input.


I have a program (foo.pl) that is designed to read the contents of @ARGV and process each item in the array. Tastes great. Less filling. So, when I do something like this, things work just fine:

%>foo.pl a b c d e f g

I have another program (bar.pl) that prints to STDOUT. The output is the same sort of data needed by foo.pl. So, I thought I'd give this is a whirl:

%>bar.pl | foo.pl

But alas, foo.pl never seems to get the input sent from bar.pl. It does not seem to read from STDIN.

This sort of situation can be dealt with with "back ticks":


foo.pl `bar.pl`

This is nice in that you can probably do this too:

foo.pl a b c `bar.pl` d e f g h `bar.pl x y z` i j k

A popular GNUism might be helpful here as well. Many GNU programs use an option command line argument of "--" to indicate that input should be taken from STDIN instead of from other command line arguments.


-- Michael McDonnell, GCIA Winterstorm Solutions, Inc. [EMAIL PROTECTED]

Reply via email to