wvbrandt has asked for the wisdom of the Perl Monks concerning the following question:
Perl Monks--I come seeking enlightenment. I've run into this problem before and have eventually given up but this time I'm going to the mountain.
I'm using a straightforward sort sub to sort various package versions out of a Maven repository like this:
sub compare_dotted_decimal { #---------------------------------------- my @a = $a =~ /(\d+)\.(\d+)\.*(\d*)\.*(\d*)\.*(\d*)/; my @b = $b =~ /(\d+)\.(\d+)\.*(\d*)\.*(\d*)\.*(\d*)/; $b[0] <=> $a[0] || $b[1] <=> $a[1] || $b[2] <=> $a[2] || $b[3] <=> + $a[3] || $b[4] <=> $a[4]; } #========================================= compare_dotted_decimal ==
This works fine. However I'd like to reuse it to compare only two values to see if the one I have is greater. It seems to me this could be called to return a -1,0,1 just like a comparison operator but everything I've tried fails to return anything. Any ideas on how to call a sort sub like a regular one?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using sort sub as regular sub
by NetWallah (Canon) on May 25, 2012 at 16:27 UTC | |
by wvbrandt (Initiate) on May 25, 2012 at 17:38 UTC |