Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: I need "Antigrep"

by ikegami (Patriarch)
on Aug 15, 2006 at 17:57 UTC ( [id://567511]=note: print w/replies, xml ) Need Help??


in reply to I need "Antigrep"

my $pattern = shift(@ARGV); my $re = qr/$pattern/; FILE: foreach my $filename (@ARGV) { open(my $fh, '<', $filename) or do { warn("Unable to open $filename: $!\n"); next; }; while (<$fh>) { next FILE if /$re/; } print("$filename\n"); }

Updated

Replies are listed 'Best First'.
Re^2: I need "Antigrep"
by tphyahoo (Vicar) on Aug 15, 2006 at 18:06 UTC
    Unfortunately doesn't work.
    hartman@ds0207:~/filesContainingArena> find | xargs hartman@ds0207:~/f +ilesContainingArena> find | xargs ./antigrep.pl c . ./a ./b ./c
    Maybe I can use that as a starting point though, so....

    UPDATE: Thanks for the update, Ikegami :)

      Fixed. $fh was going out of scope prematurely when I used

      if (!open(my $fh, '<', $filename)) { warn("Unable to open $filename: $!\n"); next; }

      I'm not sure how xargs works, but I tested it using antigrep.pl c *

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 12:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found