Sayeed Mohammed wrote:
> 
> Hello,

Hello,

> I am trying to process a log file. The format of log file is something like
> this:
> 
> datetime    code    Action    Description
> 
> The file can be between 100-200MB. The problem is that we don't know the
> code numbers in advance.
> I want to count the number of times each code entry occurred in the file.
> I would like to get the output in this format:
> 
> Code        Count
> Code#1    xxx times
> Code#2    yyy time
> ..
> and so on.
> 
> Should I make an array of each unique code and count its occurance or is
> there a better way to do it?

Use a hash for the code count:

my %code_count;

while ( <LOG> ) {
    my $code = get_code_number_somehow();
    $code_count{ $code }++;
    }

print "Code        Count\n";
for my $code ( keys %code_count ) {
    printf "%-12s%s\n" $code, $code_count{ $code };
    }

__END__


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to