in reply to Hash of Array Sort question

I have a solution but wanted to know if anyone had a easier solution for this.(like a one or 2 liner) Thanks in advance.

Show your solution

Replies are listed 'Best First'.
Re^2: Hash of Array Sort question
by sri1230 (Novice) on Mar 18, 2010 at 15:08 UTC

    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

      Sorting the elements of the array wasn't in your spec. Are you suppose to be doing that?