Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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!


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;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1049118]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2018-06-19 21:59 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (115 votes). Check out past polls.