in reply to Re: split chars in string
in thread split chars in string

How about sorting an array of words by the second character of every word? Can that be achieved without splitting the words into characters?

Replies are listed 'Best First'.
Re^3: split chars in string
by zwon (Abbot) on Nov 23, 2009 at 13:17 UTC
    #!/usr/bin/perl use strict; use warnings; use 5.010; chomp( my @words = <DATA> ); @words = sort { substr( $a, 1, 1 ) cmp substr( $b, 1, 1 ) } @words; say for @words; __DATA__ How about sorting an array of words by the second character every word
Re^3: split chars in string
by doug (Pilgrim) on Nov 23, 2009 at 14:57 UTC

    Just look at the second character.

    my @sorted_by_second = map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { [$_, substr($_,1,1)] } @unsorted;