in reply to Remove a Line
I rewrote it and left out all the fancy formatting (which really put me on the wrong track) and brought it down to the bare minimum.
As you will see when you run the program, it works perfectly and the output is as expected:
Output:use Modern::Perl; my %count; my $railcarcnt = qr(Boxcar|Reefer|Flatcar|Tankcar|Gondola|Hopper); while (<DATA>) { $count{$1}++ if /($railcarcnt)/i; } foreach my $word ( sort keys %count ) { say "There are $count{$word} $word Car(s)"; } __DATA__ B&LE:65065:Hopper:Home B&LE:65700:Hopper:Home VM:51142:Hopper:Home OS:1400:Hopper:Home HT&SF:1234:Flatcar:Away NMBS:999:Reefer:Gone
I can only guess that there must be a data issue or that the code you posted is not the code that actually ran to get you that output.There are 1 Flatcar Car(s) There are 4 Hopper Car(s) There are 1 Reefer Car(s)
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog: Imperial Deltronics
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Remove a Line
by PilotinControl (Pilgrim) on Apr 01, 2013 at 13:58 UTC |