in reply to How to sort a multidimensional array

my @data = ('Jeff Goldblum Actor', 'Mary Heartman Priest', 'John Ericsson Mathmetician', 'Tony Cisneros Chef'); use Sort::Key 'keysort'; my @sorted = keysort { (split /\s+/, $_)[2]/ } @data;

Replies are listed 'Best First'.
Re^2: How to sort a multidimensional array
by mohan123 (Novice) on Jul 11, 2006 at 10:34 UTC

    Assuming that you have your vocation as the third word
    in your array element string and ur strings delimited by exactly
    one space characters this also works

    @MYarray =( 'Jeff Goldblum Actor', 'Mary Heartman Priest', 'John Ericsson Mathmetician', 'Tony Cisneros Chef' ); @MYarray = map { join " ",@{$_} } sort { $a->[2] cmp $b->[2] } map{[sp +lit "\\s",$_]} @MYarray; use Data::Dumper; print Dumper(\@MYarray),"\n\n"; # your output should look like this .. $VAR1 = [ 'Jeff Goldblum Actor', 'Tony Cisneros Chef', 'John Ericsson Mathmetician', 'Mary Heartman Priest' ];
      This is great - I'm now trying to figure out how to get it to work with a comma-delimited array:
      Jeff,Goldblum,Actor Mary,Heartman,Priest John,Ericsson,Mathmetician Tony,Cisneros,Chef
      A reply falls below the community's threshold of quality. You may see it by logging in.