jcpunk has asked for the wisdom of the Perl Monks concerning the following question:
I am given 1,2,3,4,5 and I need back 1,5,3,4,2Example: Object => Dependency 1 => undef (no dependency) 2 => 4 3 => 5 4 => 3 5 => 1
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..
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; }
|
|---|