On Tue, Aug 09, 2005 at 06:03:18AM -0400, Jeremy Kister wrote:

> I've got an array full of hashrefs:
> my @a = ( {N => '10.1.2.1'},
>           {N => '10.1.9.1'},
>           {N => '10.3.5.1'},
>           {N => '10.1.1.3'},
>          );
> 
> I want to sort this array, and print.  I expect the output resemble:
> 
> 10.1.1.3
> 10.1.2.1
> 10.1.9.1
> 10.3.5.1
> 
> 
> I've fumbled with this for a while, and the closest I've come to is:
> my @s = map { $_ -> [0] }
>          sort { $a->[0] <=> $b->[0] ||
>                 $a->[1] <=> $b->[1] ||
>                 $a->[2] <=> $b->[2] ||
>                 $a->[3] <=> $b->[3] }
>           map { [ $_, split /\./ ] } $a->{N};

Try:

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;

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

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