in reply to Tedious array sort revisited
It sounds like a bubble sort. If you really can't use perl's sort for some reason ("capricious instructor mandates", getting a feel for perl's array operators, insanity, etc.), then you should at least know that it's quite easy to swap two values in an array with each other :
you should also consult perlop to see how <=> and cmp work, which can considerably reduce the amount of code needed to write your own sorting mechanism.
I really think this would have a different outcome if we could see what the actual assignment is. Something's not being communicated correctly. I'm not advocating that the assignment be posted, of course, but this isn't going well for anyone.
($array [$element_one], $array [$element_two]) = ($array [$element_two], $array [$element_one])
you should also consult perlop to see how <=> and cmp work, which can considerably reduce the amount of code needed to write your own sorting mechanism.
update
I really think this would have a different outcome if we could see what the actual assignment is. Something's not being communicated correctly. I'm not advocating that the assignment be posted, of course, but this isn't going well for anyone.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Tedious array sort revisited
by CountZero (Bishop) on Feb 05, 2003 at 20:17 UTC |
In Section
Seekers of Perl Wisdom