Sounds like you need to work with hash and array slices. But you'll also have to decide what you mean by "first key", "second key", etc. Hash keys don't have a meaningful ordering of their own. You have to impose the order on them from the outside:
# put keys in ascending asciibetical order my @aKeys = sort keys %hSomeHash; #put keys in descending asciibetical order @aKeys = sort { $b cmp $a } keys %hSomeHash; # @var{keys} is a hash slice # @var[number range] is an array slice @hSomeHash{@aKeys[0..4]}; #values for first 5 sorted keys @hSomeHash{@aKeys[5..9]}; #values for next 5 sorted keys # or to create a hash from the a subset of keys my %hash0_4 = map { $_ => $hSomeHash{$_} } @aKeys[0..4]; my %hash5_9 = map { $_ => $hSomeHash{$_} } @aKeys[5..9];
For more about array and hash slices, see perldata. You may also find sort and map helpful.
Best, beth
Update: added sample code for using array slice to create a subset hash
In reply to Re: A hash of a range of another hash
by ELISHEVA
in thread A hash of a range of another hash
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |