in reply to Re^2: passing parameters from shell script to perl program doesn't preserve spaces
in thread passing parameters from shell script to perl program doesn't preserve spaces [solved]
Hi peterbk,
Is there an easy way of distinguishing in perl between input from STDIN and using parameters?
For determining whether the script should use STDIN for accepting parameters, you could use the usual convention (at least for many *NIX tools) that the script has no arguments passed to it, or a single argument consisting of a dash:
my @args; if (!@ARGV || @ARGV==1 && $ARGV[0] eq '-') { @args = <STDIN> } else { @args = @ARGV }
Update: This doesn't handle quoting on the arguments passed on STDIN, but it does allow whitespace in arguments if you place the arguments each on their own lines. If you really need to parse quotes, Text::ParseWords's shellwords has already been mentioned.
Hope this helps,
-- Hauke D
|
|---|