Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: upto match please, my one-lina!!

by ioannis (Vicar)
on Jun 09, 2006 at 03:32 UTC ( #554412=note: print w/ replies, xml ) Need Help??


in reply to upto match please, my one-lina!!

So it can run also under use strict:

perl -Mstrict \ -ne'/regex(?{print @@; exit})/;' \ -e'shift(@@) if push(@@,$_)>5' file


Comment on Re: upto match please, my one-lina!!
Download Code
Replies are listed 'Best First'.
Re^2: upto match please, my one-lina!!
by NetWallah (Abbot) on Jun 09, 2006 at 04:39 UTC
    Loved the clever use of the return value from push, ioannis (++). The 'experimental' regex feature, however, got me thinking if it could be done with regular features only, so - here is the slightly ugly, but short:
    perl -ne "m/foo/ and die @@ ; shift(@@) if push(@@,$_)>5" myfile.txt
    I used "die" because (without eval), the "print @@, exit" combo printed nothing in my code (but it works as advertised in ioannis' code). Perhaps a more enlightened monk could explain why.

    Update: This works too:

    perl -Mstrict -ne "m/addr/ and eval {print @@; exit}; shift(@@) if pus +h(@@,$_)>5" myfile.txt
    This code works on Win32. Use single-quotes for *nix.

         "For every complex problem, there is a simple answer ... and it is wrong." --H.L. Mencken

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (14)
As of 2015-07-28 07:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (252 votes), past polls