http://qs1969.pair.com?node_id=284569


in reply to Hash and count of data values

You try and print a single value of the hash since the print statement is not in a loop construction.

foreach my $key (keys %hash) { print "$key $hash{$key}\n"; }
should print the collected counts.

Incidently, I don't see why you open the data file twice since you don't read any data the second time.

Personally I'd put the data in the hash while reading since this avoids slurping the whole file which can potentially be large.

my %hash; my $file = 'filehere.txt'; open(DATA, "$file") || die "Can not open: $!"; while (<DATA>) { chomp($_); $hash{$_}++; } close(DATA);

Hope this helps, -gjb-