in reply to Differentiating STDIN from arguments when using -n ?
Maybe something like this?
echo stuff | perl -ne '$x=shift; print "x=$x\n"' - myarg
It's always a good idea to tell what the expected outcome is :)
With one line of input on stdin (like your echo), this produces the same result as bart's suggestion. With more lines on stdin, however, you'd get different behaviour. Assuming that stuff is a file containing the two lines "foo" and "bar", then when doing
cat stuff | perl -ne '$x=shift; print "x=$x\n"; print "<>=$_"' - myarg + myarg2 stuff
you'd get
x=myarg <>=foo x=myarg2 <>=bar x= <>=foo x= <>=bar
i.e. you'd shift as many arguments from @ARGV as there are lines on stdin. For the remaining arguments, Perl would try to open the respective filename.
|
|---|