Jeremy Kister wrote:
I am trying to simplify some of my code.  The output I am expecting is:
1 17.0.0.1
5 27.0.0.1
5 127.0.0.1
5 209.0.0.1
6 10.0.0.1
10 127.0.1.1

where the first colomn is the main sorting column, and if there are
multiples of that value, the ip should be sorted.

I have code the performs the task, but it's a Swartzian Transform, a
temporary array, another swartz transform, and just feels icky.

any suggestions to pretty this bloat ?

my @unsorted = ( '5 127.0.0.1', '10 127.0.1.1', '5 27.0.0.1', '6 10.0.0.1', '1 17.0.0.1', '5 209.0.0.1', );

    my @sorted = map { $_->[0] } sort {
                         $a->[1] <=> $b->[1]
                                  ||
                         $a->[2] <=> $b->[2]
                                  ||
                         $a->[3] <=> $b->[3]
                                  ||
                         $a->[4] <=> $b->[4]
                                  ||
                         $a->[5] <=> $b->[5]
    } map { [ $_, split /[. ]/ ] } @unsorted;

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to