Jeremy Kister wrote:
> On 8/9/2005 6:26 AM, Paul Johnson wrote:
>>my @s = map  { $_ -> [0] }
>>        sort { $a->[0] <=> $b->[0] ||
>>               $a->[1] <=> $b->[1] ||
>>               $a->[2] <=> $b->[2] ||
>>               $a->[3] <=> $b->[3] }
>>        map  { [ $_, split /\./ ] }
>>        map  { $_->{N} } @a;
> 
> You clearly solved the problem that I asked, but... :)
> 
> I've apparently dumbed down my code and question a bit too much:  I have
> multiple hashrefs in each element of the array, and I need the resulting
> sorted array to contain all the data in the original array, simply
> sorted by the value of N.
> 
> my @a = ( {N => '10.1.2.1', ID => 1},
>           {N => '10.1.9.1', ID => 2},
>           {N => '10.3.5.1', ID => 3},
>           {N => '10.1.1.3', ID => 4},
>          );

$ perl -e'
use Socket;
use Data::Dumper;
my @a = (
    { N => "10.1.2.1", ID => 1 },
    { N => "10.1.9.1", ID => 2 },
    { N => "10.3.5.1", ID => 3 },
    { N => "10.1.1.3", ID => 4 },
    );

my @s = map  $_->[ 1 ],
        sort { $a->[ 0 ] cmp $b->[ 0 ] }
        map  [ inet_aton( $_->{ N } ), $_ ],
        @a;

print Dumper [EMAIL PROTECTED];
'
$VAR1 = [
          {
            'ID' => 4,
            'N' => '10.1.1.3'
          },
          {
            'ID' => 1,
            'N' => '10.1.2.1'
          },
          {
            'ID' => 2,
            'N' => '10.1.9.1'
          },
          {
            'ID' => 3,
            'N' => '10.3.5.1'
          }
        ];



John
-- 
use Perl;
program
fulfillment

-- 
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