There are a few changes I'd like to suggest (such as breaking this code up into functions), but answering your immediate problem, I would create a hash with each key named with a csid. Then every time you process a line, you can increment the hash entry that matches the csid. You'll end up with the hash having a unique count for each file. To create the hash, you can do this:
my %line_count;
for my $csid (@csid_list) {
$line_count{$csid} = 0;
}
Then, just before you use the counter variable in your print statement, you can do this:
++$line_count{$csid};
This will allow you to keep count on each file, even if the csids in the source file are not in sequence.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.