in reply to Re: Finding Previous and Next in a HASH
in thread Finding Previous and Next in a HASH
my %nxt;
my %prev;
my $prv;
my $first;
for (sort { $a <=> $b } keys %hash) {
$first ||= $_;
if (defined $prv) {
$nxt{$prv} = $_;
$prev{$_} = $prv;
}
$prv = $_;
}
$nxt{$prv}=$first;
$prev{$first}=$prv;
|
|---|