I had seen the "-s" option before, when reading perlrun, but had never tried using it till seeing your post. From what I can tell (on macosx 10.4.6, perl 5.8.6), it seems to work only if the script is stored in a file, and has a shebang line with this option flag -- and even then, it doesn't seem to work as advertised, unless the script is executable (runnable without passing it as an arg to "perl"):
$ 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!
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).

UPDATE: Turns out the one-liner command-line script approach actually does work if you do it like this:

$ perl -se 'print "$foo\n" if $foo' -- -foo 1 $ perl -se 'print "$foo\n" if $foo' -- -foo=bar bar
(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.

In reply to Re^2: arguments to perl -e by graff
in thread arguments to perl -e by olecs

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.