Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://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.

--J


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

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (1)
As of 2024-04-25 03:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found