There's more than one way to do things | |
PerlMonks |
about perl -s switch -- usable? evil? unneeded?by Discipulus (Canon) |
on Feb 01, 2016 at 10:53 UTC ( [id://1154173]=perlquestion: print w/replies, xml ) | Need Help?? |
Discipulus has asked for the wisdom of the Perl Monks concerning the following question:
Hello monks, Foreword During lasts weeks seems I was very active in producing oneliners (so much that I'm tempted to write some tutorial about some useful teqniques). In one oneliner where i was fixed for a parametrizable solution i come across the -s perl's switch, that i admit I was completely unaware of. In perlrun few lines are dedicated to it. It is somtehing difficult to search informantions for, but I found:
From what i understand from official docs it works on the shebang line: it must also run from command line for oneliners and other programs too. Let's see what I tested given simple.pl program as follow:
Ie $test is set by the commandline switch -test=SET_VIA_-s and is visible in the BEGIN then the body of the program gives it another value original value Why this does not deparse to anything visible (as opposite of other switches like -l -n -p -a -F )?
while in the oneliner version (without strict and warnings) And using the -- termintation of switch processing it works fine:
But adding strict and warnigs and the my declaration for $test (as in simple.pl ) the oneliners version gives different results:
In addition the evil behaviour explained in the above mentioned thread is still active, and evem more incomprensible if you add a qq(..)
personal conclusions about -s switch
It is said in perlrun that enables rudimentary switches. It is not too reductive word?. Is not worth to spend some word more in the official docs, explaining that MUST be used only in oneliners to act as rudimentary switch's processor (only oneliners examples, not short script)? Are my conclusions correct? Cannot be that switch a candidate to be removed? Why it's usage does not deparse to something visible? what the hell in the last example? 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.
Back to
Seekers of Perl Wisdom
|
|