Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

From perlrun:

(-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 --). This means you can have switches with two leading dashes (--help). Any switch found there is removed from @ARGV and sets the corresponding variable in the Perl program. The following program prints "1" if the program is invoked with a -xyz switch, and "abc" if it is invoked with xyz=abc.

#!/usr/bin/perl -s if ($xyz) { print "$xyz\n" }

Do note that --help creates the variable ${-help}, which is not compliant with "strict refs".

Now, this last thing is really enough for me. I use strict in just about everything I write that I intend to actually use, since it has found about a zillion things that I've done wrong in the past.

People also pointed out that using -s is pretty much a giant security hole and can lead to the unanticipated creation of strange and interesting variables. Another compelling argument (to me, anyway) is that the docs themselves call this a 'rudimentary switch parsing' method, whereas Getopt::Std and Getopt::Long are more complete ways of doing this.

So what? Where's the question? Right here: There's a guy in my office who likes -s. He says that the first time he did a Google search on using command-line arguments with Perl, a link to an article that suggested -s was the top hit. He also says that since he is the only one that uses his scripts and because he does validation on the variables so passed, the security risks are moot.

So does anyone have a really strong reason NOT to use -s? It seems both kludgy and dangerous to me, but I'm not having fun trying to convince him. Any advice is welcome.


In reply to Is using '-s' really bad and why? by Rhys

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (8)
    As of 2020-11-24 06:42 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found