in reply to Sorting by association, a tail of dependency resolving gone nowhere
If your data is indeed stored in a hash you could do something like:
substituding the print statement with whatever is needed for your larger application. Note that my example works if two keys have the same dependency. And you'll get a warning about uninitialzed value when it tries to print $sortme{1};#!/usr/bin/perl -w use strict; my (%sortme, $k); %sortme = ( 1 => undef, 2 => 4, 3 => 5, 4 => 3, 5 => 1, 6 => 3 ); foreach $k ( sort { return -1 if !defined $sortme{$a}; return 1 if !defined $sortme{$b}; $sortme{$a} <=> $sortme{$b}; } keys %sortme ) { print "$k -> $sortme{$k}\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sorting by association, a tail of dependency resolving gone nowhere
by Roy Johnson (Monsignor) on Dec 12, 2005 at 18:16 UTC | |
by mikeraz (Friar) on Dec 12, 2005 at 18:25 UTC |