Perl-Sensitive Sunglasses | |
PerlMonks |
Re: How to compare elements within an arrayby kcott (Archbishop) |
on Feb 23, 2014 at 08:33 UTC ( [id://1075875]=note: print w/replies, xml ) | Need Help?? |
G'day doubleqq, Here's another way to do it. This solution only uses a single loop and pulls two elements at a time from the array (using splice). If a pair wasn't found, the second element (if it exists) is put back on the array for retesting on the next iteration.
Output:
Update: Made some changes to the code and added some additional tests. Old code (and old output) in spoiler below. <Reveal this spoiler or all in this thread>
-- Ken
In Section
Seekers of Perl Wisdom
|
|