That's how it's supposed to act. If you don't want the value, change the last 4 lines to this:

 

foreach my $number (keys %countother)
{
        print "$number\n";
}

You need to specify keys if you don't want the value to also be printed.

 

Steve H.

 

-----Original Message-----
From: Peter Eisengrein [mailto:Peter.Eisengrein@atx.com]
Sent: Friday, November 22, 2002 6:39 AM
To: Perl-Win32-Gui-Users (E-mail)
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";
}

- This message (including any attachments) contains confidential information intended for a specific individual and purpose, and is protected by law. - If you are not the intended recipient, you should delete this message and are hereby notified that any disclosure, copying, or distribution of this message, or the taking of any action based on it, is strictly prohibited.