KW.pm The Schwartzian Transform #16

       @split = map { [ split ] } @names;
       @sort = sort { $a->[1] cmp $b->[1]
                       || $a->[0] cmp $b->[0] } @split;
       @sorted_names = map { join ' ', @$_ } @sort;

We can chain together the steps:

        @sorted_names = 
            map  { join ' ', @$_ }
            sort { $a->[1] cmp $b->[1]
                  || $a->[0] cmp $b->[0] }
            map  { [ split ] } @names;

 

<< Previous | Index | Next >> Copyright © 2003 Daniel Allen