in reply to Unable to get counter to reset
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.
|
|---|