in reply to Re: Re: Re: Re: Re: Simple hash assignment...or is it?
in thread Simple hash assignment...or is it?
To print the values in a hash, use the keys keyword.
my %hash = ( 'a' => 1, 'b' => 2, 'c' => 3);
foreach (keys %hash) {
print "$_ => $hash{$_}\n";
}
Cheers. :-)
In general, I wouldn't say that. "keys" is a standard Perl function (not a keyword), of which you can omit the () because there is a prototype known for it. Furthermore:
my @value = values %hash;
my @key = keys %hash;
my @value = sort values %hash; my @key = sort keys %hash; foreach (sort keys %hash) { print "$_ => $hash{$_}\n"; }
while (my $key = each %hash) { print "$key\n"; } while (my ($key,$value) = each %hash) { print "$key => $value\n"; }
Liz
|
|---|