Hello!

yesterday I was trying some perl code after neverending boring weeks (workwise..) and I tried to use -s to add rudimentary switch parsing as described here (emphasis added by me):

> -s enables rudimentary switch parsing for switches on the command line after the program name but before any filename arguments (or before an argument of --).

The above is true when there is a real file containing a perl program:

echo print join ' ', $0, $R > switch-test.pl # after the program name perl -s switch-test.pl -R=OK switch-test.pl OK # before an argument of -- perl -s switch-test.pl -R=OK -- switch-test.pl OK # wrong usage perl -s switch-test.pl -- -R=OK switch-test.pl

But what if the program is just some code passed with -e (and this is a valid program also for the program name perl's internal value)?

Even with my limited English understanding, I'd suppose something like: perl -s -e "print $R" R=a or perl -s -e -n "print $R" R=a filename (before any filename arguments) but no, it works exactly in the opposite way:

# after the program name perl -s -e "print join ' ', $0, $R" -R=OK Unrecognized switch: -R=OK (-h will show valid options). # before an argument of -- perl -s -e "print join ' ', $0, $R" -R=OK -- Unrecognized switch: -R=OK (-h will show valid options). # it works in the opposite way of what perlrun states perl -s -e "print join ' ', $0, $R" -- -R=OK -e OK

So, given the switch is stated as rudimentary one should expect to use with small oneliners (only our dead pope used it as signature..) and not for serious programs.

In combination with other switches is even unfriendly:

perl -snwe "print join ' ', $0, $R, $/" -- -R=OK lorem.txt -e OK -e OK -e OK -e OK

..as it shuold be put before any file name but after the --

The docs also warns about warnings:

> Also, when using this option on a script with warnings enabled you may get a lot of spurious "used only once" warnings.

..but no... or.. what happens??

perl -wse "print join ' ', $0, $R" -- -R=OK -e OK perl -swe "print join ' ', $0, $R" -- -R=OK -e OK perl -sew "print join ' ', $0, $R" -- -R=OK #what the hell?! ..no output :)

I think the doc should metion the above. More: in this sight also -- is poorly documented.

Want some monk put a pr somewhere or point me, lazy peon, to the correct repository to strike?

Have a nice weekend!

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to perlrun doc inaccurate on -s switch by Discipulus

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.