Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: about perl -s switch -- usable? evil? unneeded?

by Eily (Monsignor)
on Feb 01, 2016 at 13:05 UTC ( [id://1154183]=note: print w/replies, xml ) Need Help??


in reply to about perl -s switch -- usable? evil? unneeded?

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).

  • Comment on Re: about perl -s switch -- usable? evil? unneeded?

Replies are listed 'Best First'.
Re^2: about perl -s switch -- usable? evil? unneeded?
by Discipulus (Canon) on Feb 01, 2016 at 22:16 UTC
    Thanks for spotting my error; maybe i've done too much test and i become mazed. i've put a comment in the above code pointing to your precious answer.

    I'm with you in your second paragraph too. I have not fear of (Perl's) dangerous things (and if you search for mine usage of eval string you can say i hazard..) but i also like to know when something is flammable. The last test (ovverding $1 above) was chocking for me. I'd like at least be adviced by the perlrun man page.

    More: the -s inanity respect variables declared with my and the few words dedicated to it let me think of some vestige from the past. Imagine if -s had the ability to modify lexical variables in the main package just after their first declaration: with this ipothetic functionality you would be able to ovveride some default value to test your program in seconds, from command line. Like a totally new environment.

    If I remember correctly -s is in the default shebang of some valuable monk here around.

    Many question are still open for me as why it not deparse to nothing and why the last behaviour ovverriding or not a readonly variable depending on the qq()

    At the end I confess i found not enough information to have my curiosity satisfied and i hoped this post could get some interesting contribution from them who know more.

    thanks again for your keen sight and your opinion.

    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1154183]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-18 05:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found