OK. I had another look at your program.

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:

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
Output:
There are 1 Flatcar Car(s) There are 4 Hopper Car(s) There are 1 Reefer Car(s)
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.

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

In reply to Re: Remove a Line by CountZero
in thread Remove a Line by PilotinControl

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.