hello haukex,

Yes, thanks, a neat little trick.

It will be useful, for example, in unfortunate shells that does not do glob expansions of the arguments. To count lines of code in test files you can glob them using your trick (I was used to put a BEGIN block there):

perl -M"5;@ARGV=glob shift" -lnE "last if /__DATA__/;$c++ unless /^$|^ +\s*#/}{say $c" "./t/*.t"

I didnt recognize what that 5 was for; manual to the rescue! require N requires a minimal version of Perl, so numbers from 0 to 5 will be all ok. Zero is more hackish ;)

This neat trick is worth to be added to shh.. dont tell! manpage (update: done!). If I can suggest a name, being the opposite of eskimo greeting I propose maori farewell

That said, i cant resist to use the maori farewell immediately..

perl -M"0;eval{require 6},@}=(40,35,0,32)" -e "print map{chr(ord($_)-s +hift@})}(split'',$@)[12,19,0,23]" # linux quoting: perl -M'0;eval{require 6},@}=(40,35,0,32)' -e 'print map{chr(ord($_)-s +hift@})}(split"",$@)[12,19,0,23]'

L*

UPDATE April 25 2019: in December I suggested to add this trick to perlsecret and is now part of perlsecret 1.014

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.

In reply to Re: Inserting Code Before an -n/-p Loop -- oneliner by Discipulus
in thread Inserting Code Before an -n/-p Loop by haukex

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.