Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Perl as grep (-p/next)

by tye (Sage)
on Dec 02, 2003 at 18:36 UTC ( [id://311709]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl as grep
in thread Perl as grep

duff++

Note that one of your examples:

perl -pe "next unless /regex/" *.*
doesn't do what you think. -p puts the print statement in the while(<>) loop's continue block and so it will get called when you call next. So that one-liner prints all lines of a file named "*.*" (yes, you are correct about globbing, much to my consternation -- the reasons for this are nonsense), just not as efficiently because it applies a regex to each line and then effectively ignores the result of that test.

                - tye

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-20 03:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found