ddrew78 has asked for the wisdom of the Perl Monks concerning the following question:
What I need to do is count the occurrance of each, so the output based on the above should beCS MS CS AT AV MS
I figured the easiest way would be to do this using an array, but what I have below does not give me what I need.CS1 MS1 CS2 AT1 AV1 MS2
Any suggestions?open(PBXNUM1, ">pbxnum1"); open(MYINPUTFILE, "pbxnum"); $nt = 0; $ms = 0; $ap = 0; $cs = 0; $em = 0; $at = 0; $av = 0; $to = 0; while (<MYINPUTFILE>) { my($line) = $_; chomp($line); $nt++; $ms++; $ap++; $cs++; $em++; $at++; $av++; $to++; @mypbx = ('NT', 'MS', 'AP', 'CS', 'EM', 'AT', 'AV', 'TO'); foreach $mypbx (@mypbx) { print PBXNUM1 "$line$mypbx\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Counting within an array
by happy.barney (Friar) on Nov 30, 2010 at 13:48 UTC | |
by kennethk (Abbot) on Nov 30, 2010 at 14:04 UTC | |
by ddrew78 (Beadle) on Nov 30, 2010 at 14:12 UTC | |
|
Re: Counting within an array
by locked_user sundialsvc4 (Abbot) on Nov 30, 2010 at 14:22 UTC | |
|
Re: Counting within an array
by ambrus (Abbot) on Dec 01, 2010 at 11:01 UTC |