Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Inserting Code Before an -n/-p Loop -- oneliner

by Discipulus (Canon)
on Dec 18, 2018 at 09:32 UTC ( [id://1227382]=note: print w/replies, xml ) Need Help??


in reply to Inserting Code Before an -n/-p Loop

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.

Replies are listed 'Best First'.
Re^2: Inserting Code Before an -n/-p Loop -- oneliner
by Anonymous Monk on Dec 18, 2018 at 18:04 UTC

    Zero is more hackish ;)

    "-6"!! That will teach them a lesson!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1227382]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2025-07-18 07:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.