Pete, You forgot the 'keys' in your foreach statement.
ie foreach my $number (%countother) should be foreach my $number ( keys %countother) otherwise the foreach loops through both keys and values. Cheers, Kev. |---------+------------------------------------------------> | | Peter Eisengrein | | | <[EMAIL PROTECTED]> | | | Sent by: | | | [EMAIL PROTECTED]| | | ceforge.net | | | | | | | | | 22/11/2002 14:38 | | | | |---------+------------------------------------------------> >----------------------------------------------------------------------------------------------| | | | To: "Perl-Win32-Gui-Users (E-mail)" <perl-win32-gui-users@lists.sourceforge.net> | | cc: | | Subject: [perl-win32-gui-users] odd hash behavior | >----------------------------------------------------------------------------------------------| The script below outputs the correct $number (hash key) but for some reason it also outputs the value. What gives? -Pete ############################### use strict; my %countother; print "File: "; chomp(my $file=<STDIN>); open(FILE,$file) || die "can't open file : $!\n"; foreach (<FILE>) { chomp($_); my @line = split(/\,/,$_); my ($number) = $line[8] =~ /\"(.*)\"/; $countother{$number}++; } close(FILE); my $count = keys %countother; print "Total of $count numbers used in ~ 1 week.\n"; print "*****************************************************\n"; print "NUMBER CALLS\n"; foreach my $number (%countother) { print "$number\n"; }