in reply to Re: What makes an array sorted and a hash unsorted?
in thread What makes an array sorted and a hash unsorted?
If you say values %hash to get the values of a hash, they will be in no particular order.
So if the following change was built into Perl, hashes would be considered sorted?
use subs qw( values ); sub values(\%) { my $h = shift; return keys(%$h) if !wantarray(); my @keys = sort keys(%$h); return @{$h}{@keys}; }
my %h = map { $_ => $_ } 'a'..'z'; print(values(%h), "\n"); # abcdefghijklmnopqrstuvwxyz
I think there's more to it than just this change in the builtin accessors.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: What makes an array sorted and a hash unsorted?
by Roy Johnson (Monsignor) on Jun 01, 2009 at 17:45 UTC | |
by ikegami (Patriarch) on Jun 01, 2009 at 17:54 UTC | |
by Roy Johnson (Monsignor) on Jun 01, 2009 at 18:07 UTC | |
by ikegami (Patriarch) on Jun 01, 2009 at 18:12 UTC | |
by Roy Johnson (Monsignor) on Jun 01, 2009 at 18:45 UTC | |
|
In Section
Meditations