I have searched google and thepen to no avail (my guess is that I am not searching for the right stuff) thus I appeal to you...
I am writting a function where I will be given a list of items that are selected. Each of these items (save one) has a dependency on another of those items. I need to sort them in order of dependency.

Example: Object => Dependency 1 => undef (no dependency) 2 => 4 3 => 5 4 => 3 5 => 1
I am given 1,2,3,4,5 and I need back 1,5,3,4,2

Here is my failed attempt at solving this... Could I ask that someone show me either what I have missed that makes it loop endlessly or a far simpler way of doing this..

%ArgHash is structued $ArgHash{$version}=csv,list,of,selected
and bubble sort stinks but I cannot think of a different way to do this...I am unenlightened
sub sortPatch { my %ArgHash=@_; my $version = join('',keys(%ArgHash)); my @tbs = split(/\,/,$ArgHash{$version}); my @LoopControl=@tbs; my @returning; foreach (@tbs,(1)) # this should make it go one more time... right? { my ($previous,$patchlist); foreach my $patch (@LoopControl) { undef($previous); undef($patchlist); $previous=$PatchInfo::patch{$version}{$patch}{'PREVIOUS'} if (de +fined($PatchInfo::patch{$version}{$patch}{'PREVIOUS'})); $patchlist = join('|',@returning); if (defined($previous)) { if (($previous ne '') and (not($previous =~ /$patchlist/))) { my $selected = join('|',@tbs); if (($previous =~ /$selected/) and ($selected ne '')) { push(@returning,$previous); } } } push(@returning,$patch); } @LoopControl=(); @LoopControl=@returning; } return @returning; }

jcpunk
help?

In reply to Sorting by association, a tail of dependency resolving gone nowhere by jcpunk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.