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.

— Ken


In reply to Re^4: Need script help [aliases and function] by kcott
in thread Need script help by jmckinzie

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.