----- Original Message -----
From: Wang, Lanbo <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, June 30, 2001 12:04 AM
Subject: Problem with hash value
> Hi Members,
>
> It seemed that a value was incorrectly retrieved from the hash list in the
> following small Perl script. .
>
> #!/usr/local/bin/perl
>
> sub card{
>
> my %card_map;
> my ($num)=@_;
> @card_map{1..9}= qw(one two three four five six seven eight nine);
You are putting the numbers 0..9 in the array @card_map here, not in the
hash %cardmap.
Those are different things.
You should acces the array instead.
Another top is to declare and fill @card_map outside the function.
It only needs to be filled once.
Tru this:
#!/usr/local/bin/perl
my @card_map{1..9}= qw(one two three four five six seven eight nine);
sub card{
return $card_map[$_[0]] || $_[0];
}
while (<>) {
chomp
print "card of $_ is:" &card($_), "\n";
}
Maarten