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

Re: Better way of doing!

by jwkrahn (Monsignor)
on Aug 12, 2013 at 13:07 UTC ( #1049118=note: print w/ replies, xml ) Need Help??


in reply to Better way of doing!

while(<@eachline>){

You are interpolating the array @eachline in a double quoted context and then using the glob function on the resulting string:

$ perl -MO=Deparse -e'while(<@eachline>){}' use File::Glob (); while (defined($_ = glob(join($", @eachline)))) { (); } -e syntax OK

this is a very obtuse way to split a string on whitespace:

$ perl -le'my @eachline = ( "one two three four\n", "five six seven ei +ght\n" ); while(<@eachline>){print}' one two three four five six seven eight

It looks like you may want something like this:

use strict; use warnings; open my $FILEHANDLE, "<", "Action5.c" or die "cannot open < Action5.c: + $!"; my %patterns = ( transaction => 0, find => 0, think => 0, save_param => 0, start_sub => 0, url => 0, submit => 0, ); while ( my $line = <$FILEHANDLE> ) { for my $pattern ( keys %patterns ) { $patterns{ $pattern } += () = $line =~ /$pattern/g; } } for my $pattern ( keys %patterns ) { print "Number of patterns found for".$pattern." is ".$patterns{ $p +attern }."\n"; } close $FILEHANDLE;


Comment on Re: Better way of doing!
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (12)
As of 2015-07-03 16:11 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 (54 votes), past polls