Your first output doesn't match your first program, since the variable $test is not printed in the BEGIN block. I suppose this is because you couldn't compile with strict, the solution to that is to declare the variable with our (which will just alias $test to $main::test). Having lexicals override package variables, and our variables (locally aliased? I can't remember if there's a standard name for those) is true even without the -s switch. Actually the $test in the BEGIN block and the $test after the my declaration are two different variables that happen to have the same name. Without strict, the fact that a -s variable is a package global can be implicit.

On the main subject now, on whether -s should be used/kept: I like that perl allows unsafe but useful features that you can use for oneliners and other throwaway code. So having an option with some caveats is OK for me, I just try to avoid them when I'm not writing in a console. The thing is, having a "rudimentary switch" mechanism for any kind of program means that you intend to use it several times, or even that you may not be the only one to use it. For me this is not compatible with the shortcomings of -s, so I would never use it. But I like how perl's philosophy is to "give the user enough rope to hang themselves" but tell them how to avoid the pitfalls, rather than try to secure everything and remove the need for a better understanding. So remove -s, why not? But since it is little known option, and it does have its advantages when used correctly, I don't think it's that much of a hazard (unlike <> or the two parameters open, which are not only really common, but also more standard).


In reply to Re: about perl -s switch -- usable? evil? unneeded? by Eily
in thread about perl -s switch -- usable? evil? unneeded? 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.