Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Reading through a file and checking for a specific string

by BillKSmith (Chaplain)
on Aug 20, 2013 at 12:41 UTC ( #1050176=note: print w/ replies, xml ) Need Help??


in reply to Reading through a file and checking for a specific string

This is one of the rare cases where I would recommend slurping the entire file rather than reading line-by-line. I feel that the simplification justifies the use of much more memory.

#!/usr/bin/perl use warnings; use strict; use Slurp; use Data::Dumper; my $strings = join '|', qw( AB AC AD AE FG ); my $counts; for my $file (glob ('File/*')) { $counts->{$_}++ foreach (Slurp($file) =~ m/($strings)/gms); } print Dumper($counts);
Bill


Comment on Re: Reading through a file and checking for a specific string
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2014-07-30 22:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (241 votes), past polls