http://www.perlmonks.org?node_id=995253


in reply to Re: counting elements using a hash
in thread counting elements using a hash

here is my revised code and it's working like a charm I the file contains only numbers (integers and decimals), no zeros, thank you all for your input

my $INPUT_FILE; my $OUTPUT_FILE; my %count; open ($INPUT_FILE, "< " ) or die "Can't open file"; open ($OUTPUT_FILE, ">output") or die "can't open output file"; while($number = readline($INPUT_FILE)){ $count{$number}++; } foreach $number(sort keys %count){ print "$number occurs $count{$number} times(s)\n"; } close ($OUTPUT_FILE) or die "Can't close file!!!";