activePerl 5.8 based
#!C:\\Perl\\bin\\perl.exe
use strict;
use warnings;
# declare a new hash
my %some_hash;
%some_hash = (\"foo\", 35, \"bar\", 12.4, 2.5,
Hashes are not (necessarily) retrieved in a sorted manner. If you want them sorted, you have to do it yourself:
use strict;
use warnings;
my %hash = ("a" => 1, "b" => 2, "c" => 3, "d" => 4);
for my $i (sort keys %hash) {
print "$i -> $hash{$i}\n";
}
You retrieve all the keys from a hash by using keys
and you then sort them using sort
. Yeah, I know, that crazy Larry Wall guy, who would've ever thought of calling them that? :-)
This outputs:
a -> 1
b -> 2
c -> 3
d -> 4