Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: perl grep clone (CLI & perlrun)

by LanX (Saint)
on Apr 02, 2016 at 12:07 UTC ( [id://1159363]=note: print w/replies, xml ) Need Help??


in reply to perl grep clone

I have the impression your motivation comes from the desire to emulate grep from command line.

So maybe you want to have a look at -l -a -n -e -p ...(and so on) options in perlrun ?

e.g.

-n

causes Perl to assume the following loop around your program, which makes it iterate over filename arguments somewhat like sed -n or awk:

LINE: while (<>) { ... # your program goes here }

Note that the lines are not printed by default. See -p to have lines printed. If a file named by an argument cannot be opened for some reason, Perl warns you about it and moves on to the next file.

update

As replacement for

grep PATTERN *

try

perl -ne'/PATTERN/&&print' *

for a start. :)

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-26 02:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found