Here is what i am doing I am sorting and using the index instead of actually writing it as a value in array
my $hash; foreach my $csn (keys %$datastore) { push @{$hash->{$datastore->{$csn}->[3]}}, $datastore->{$csn}->[0]; } foreach (keys %$hash) { my @sorted = sort { $a <=> $b } @{$hash->{$_}}; $hash->{$_} = \@sorted; } foreach (keys %$datastore) { $datastore->{$_} = [$datastore->{$_}->[1],$datastore->{$_}->[2],$d +atastore->{$_}->[3], indexof($hash->{$datastore->{$_}->[3]}, $datasto +re->{$_}->[0])]; } sub indexof{ my ($array_ref, $search_for) = (shift, shift); my @array = @$array_ref; my( $index )= grep { $array[$_] eq $search_for } 0..$#array; return ($index + 1); }
Created an other hash with each unique d as key and value is a array ref with sorted a's and then use the index
In reply to Re^2: Hash of Array Sort question
by sri1230
in thread Hash of Array Sort question
by sri1230
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |