in reply to can someone plz decode this sort for me?
For example:
prints%g2o = ( 128 => 'a', 13 => 'b', 34 => 'a', 28 => 'c' ); @allgs = (128, 13, 34 ); @allgsplane = sort { ($g2o{$a} cmp $g2o{$b}) || ($a <=> $b) } @allgs; print "@allgsplane\n";
All items with the value 'a' in the hash (34, 128) come before the item with value 'b' (13), because 'a' comes before 'b', but since there are two items with 'a', the smaller one (34) comes before the larger one (128).34 128 13
Note that my hash contains more items than the list I'm sorting, but those will simply be ignored.
If the hash contains fewer items than the list, then it'll still work, with the missing items getting a default value of 0 (actually undef, but numerically, that is 0), but with "use of unitialized value" warnings.
|
|---|