Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

by BillKSmith (Deacon)
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 scrutinizing the Monastery: (12)
As of 2015-07-29 21:19 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 (269 votes), past polls