go ahead... be a heretic | |
PerlMonks |
Re: Sort Algorithm (recursive?)by BrowserUk (Patriarch) |
on Oct 14, 2005 at 15:22 UTC ( [id://500257]=note: print w/replies, xml ) | Need Help?? |
This does the job for your simple case with the only recursion necessary is that embedded inside Perl's builtin sort. UpdateHowever, if your structure could have circular dependancies that are indirect--ie. A depends on B depends on C depends on A.--then this will not detect that. Making it more efficient is the next challenge, but maybe that doesn't matter if your hash is smallish. Updated to use @{} instead of $#{}. With thanks to Roy Johnson
A somewhat more efficient version curtesy of the Orcish Manouver(?) and List::Util::first that avoids modifying your datastructure. </reduce> Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
In Section
Seekers of Perl Wisdom
|
|