in reply to Re: arguments to perl -e
in thread arguments to perl -e
So -s is just not suitable for use with a one-liner script on the command line. Oh well. At least there are other ways of doing this sort of thing (as indicated by earlier replies).$ perl -s -foo=bar -e 'print $foo,$/ if $foo' Unrecognized switch: -foo=bar (-h will show valid options). # (and similarly with other arrangements of these args) $ cat junk.pl #!/usr/bin/perl -s print "$foo\n" if $foo; $ perl junk.pl $ perl junk.pl -foo 1 $ perl junk.pl -foo=bar 1 # (I thought that should have printed "bar", but # there must be some logical reason why it didn't.) $ chmod +x junk.pl $ junk.pl $ junk.pl -foo 1 $ junk.pl -foo=bar bar # at last!
UPDATE: Turns out the one-liner command-line script approach actually does work if you do it like this:
(thanks to blockhead for pointing this out to me.) There was something about the double-dash arg in the perlrun description of "-s", but it didn't seem to apply to this facet of perl's behavior.$ perl -se 'print "$foo\n" if $foo' -- -foo 1 $ perl -se 'print "$foo\n" if $foo' -- -foo=bar bar
|
|---|