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.
should print the collected counts.foreach my $key (keys %hash) { print "$key $hash{$key}\n"; }
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-
In Section
Seekers of Perl Wisdom