Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hello Monks, I am trying to find keyword count from a file as below:
use strict; use warnings; my $i=0; my $j=0; my $k=0; my $l=0; my $m=0; my $n=0; my $o=0; open(my $FILEHANDLE, "<", "Action5.c") or die "cannot open < Action5.c +: $!"; my @eachline = <$FILEHANDLE>; my @patterns = (qr/transaction/, qr/find/, qr/think/, qr/save_param/, +qr/start_sub/, qr/url/, qr/submit/); my $count = @eachline; while(<@eachline>){ if ($_ ~~ $patterns[0]){$i++;} elsif($_ ~~ $patterns[1]){$j++;} elsif($_ ~~ $patterns[2]){$k++;} elsif($_ ~~ $patterns[3]){$l++;} elsif($_ ~~ $patterns[4]){$m++;} elsif($_ ~~ $patterns[5]){$n++;} elsif($_ ~~ $patterns[6]){$o++;} } print "Number of patterns found for".$patterns[0]." is ".$i."\n"; print "Number of patterns found for".$patterns[1]." is ".$j."\n"; print "Number of patterns found for".$patterns[2]." is ".$k."\n"; print "Number of patterns found for".$patterns[3]." is ".$l."\n"; print "Number of patterns found for".$patterns[4]." is ".$m."\n"; print "Number of patterns found for".$patterns[5]." is ".$n."\n"; print "Number of patterns found for".$patterns[6]." is ".$o."\n"; close($FILEHANDLE);
This is a very crude way,I know. Please guide me with a better code. Regards, Xhings

In reply to Better way of doing! by Xhings

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-03-28 18:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found