yesterday I was trying some perl code after neverending boring weeks (workwise..) and I tried to use -s to add rudimentary switch parsing as described here (emphasis added by me):
> -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 --).
The above is true when there is a real file containing a perl program:
echo print join ' ', $0, $R > switch-test.pl # after the program name perl -s switch-test.pl -R=OK switch-test.pl OK # before an argument of -- perl -s switch-test.pl -R=OK -- switch-test.pl OK # wrong usage perl -s switch-test.pl -- -R=OK switch-test.pl
But what if the program is just some code passed with -e (and this is a valid program also for the program name perl's internal value)?
Even with my limited English understanding, I'd suppose something like: perl -s -e "print $R" R=a or perl -s -e -n "print $R" R=a filename (before any filename arguments) but no, it works exactly in the opposite way:
# after the program name perl -s -e "print join ' ', $0, $R" -R=OK Unrecognized switch: -R=OK (-h will show valid options). # before an argument of -- perl -s -e "print join ' ', $0, $R" -R=OK -- Unrecognized switch: -R=OK (-h will show valid options). # it works in the opposite way of what perlrun states perl -s -e "print join ' ', $0, $R" -- -R=OK -e OK
So, given the switch is stated as rudimentary one should expect to use with small oneliners (only our dead pope used it as signature..) and not for serious programs.
In combination with other switches is even unfriendly:
perl -snwe "print join ' ', $0, $R, $/" -- -R=OK lorem.txt -e OK -e OK -e OK -e OK
..as it shuold be put before any file name but after the --
The docs also warns about warnings:
> Also, when using this option on a script with warnings enabled you may get a lot of spurious "used only once" warnings.
..but no... or.. what happens??
perl -wse "print join ' ', $0, $R" -- -R=OK -e OK perl -swe "print join ' ', $0, $R" -- -R=OK -e OK perl -sew "print join ' ', $0, $R" -- -R=OK #what the hell?! ..no output :)
I think the doc should metion the above. More: in this sight also -- is poorly documented.
Want some monk put a pr somewhere or point me, lazy peon, to the correct repository to strike?
Have a nice weekend!
L*
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: perlrun doc inaccurate on -s switch
by jo37 (Curate) on Nov 22, 2024 at 10:20 UTC | |
Re: perlrun doc inaccurate on -s switch
by ikegami (Patriarch) on Nov 23, 2024 at 18:08 UTC | |
by etj (Priest) on Nov 24, 2024 at 18:38 UTC |