G'day shmem,
++
That goes some way to corroborating my
«I don't think it would actually make any of my scripts "non-portable"».
Tired of continually having to add ' -E to multiple perlo calls when testing,
I wrote the alias
[perle = perl + options and execute]
to do it for me.
There are certain local usages of Perl where I don't want these pragmata:
when using B::Deparse being a prime example.
In these cases, having PERL5OPT set would be less than optimal.
As these have, more or less, boilerplate command lines,
I wrote the aliases [perlb = perl + B::Deparse]
(which includes the '-p' option, to print extra parentheses
— useful when checking complex predence rules)
and [perlr = perl + B::Deparse raw]
(which includes no options
— useful when seeing how the code is parsed without the distraction of a forest of parentheses).
My .bash_aliases (sourced by .bash_profile) now includes:
alias perlo='perl -Mstrict -Mwarnings -Mautodie=:all'
alias perle='perl -Mstrict -Mwarnings -Mautodie=:all -E'
alias perlb='perl -MO=Deparse,-p -e'
alias perlr='perl -MO=Deparse -e'
Now I can write, for example:
$ perlo -E 'my $x; $x = 41; ++$x; say $x'
42
$ perle 'my $x; $x = 41; ++$x; say $x'
42
$ perlb 'my $x; $x = 41; ++$x; say $x'
my($x);
($x = 41);
(++$x);
$x->say;
-e syntax OK
$ perlr 'my $x; $x = 41; ++$x; say $x'
my $x;
$x = 41;
++$x;
$x->say;
-e syntax OK
I also considered other common usages that might have boilerplate command lines.
I often use Perl as a handy calculator (e.g. perl -E 'say($calculation_result)').
I wrote the function [perls = perl + say()].
My .bash_functions (also sourced by .bash_profile) now includes:
perls () {
eval "echo \`perl -T -Mstrict -Mwarnings -Mautodie=:all -E '
my \$ev = eval \"$@\";
say defined \$ev ? \"\$ev\" : \"$@\";
'\`"
}
Now I can write, for example:
$ perls 1 + 1
2
$ perls 67 / 33
2.03030303030303
$ perls \(67 / 33\) + 1
3.03030303030303
$ perls '(67 / 33) + 1'
3.03030303030303
$ perls 'my \\\$x; \\\$x = 41; ++\\\$x'
42
$ perls `perle 'my $x; $x = 41; ++$x; say $x'`
42
$ perle 'my $x; $x = 41; ++$x; say $x'
42
$ perls Hello, world!
Hello, world!
Setting PERL5OPT globally is not useful for me;
however, I don't discount its use in limited scope.
|