# Unrealistic to store 400000 names in an
array.
# A more practical solution may look like
this:
$FileName = '....your file name
here....';
$ResultFile = '...your output file
here....';
open ( INPUT, $FileName ) or die "Cannot open [$FileName]:
$!\n";
open ( OUTPUT, ">$ResultFile" ) or die "Cannot open:
[$ResultFile] $!\n";
my
%hash;
while ($Line
=<INPUT>)
{
chomp
$Line;
$hash{$Line}++;
}
close
INPUT;
for
$key (keys %hash) {
print
OUTPUT "Name: $key count = $hash{$key}\n";
}
close OUTPUT;
Eugene Hiamov
-----Original Message-----
From: Mumper, Jay [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 06, 2002 11:10 AM
To: 'Heiko Nieke'; [EMAIL PROTECTED]
Subject: RE: Count how often a certain element occurs in an arraySomething likemy %hash;for (my $i=0;$i<@array;$i++) {if (!$hash{$array[$i]}) {$hash{$array[$i]} = 1;} else {$hash{$array[$i]}++;}}foreach $key (keys %hash) {print "Name: $key count = $hash{$key}\n";}-- Jay Mumper-----Original Message-----
From: Heiko Nieke [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 06, 2002 11:03 AM
To: [EMAIL PROTECTED]
Subject: Count how often a certain element occurs in an arrayHi,
It might be a silly question, but I am new to perl and I need to solve the following problem
- I have a list with approx. 400000 names
for example:
Christian
Sally
Christian
Klaus
....Now I need to know how often each name appears in the list. Could anybody help me doing this with a perl script?
Thanks
Heiko
