Hardly Armchair wrote:
> Hello List,
Hello,
> I have a data structure containing a bunch of strings in different groups:
>
> $groups = [
> [
> 'SSPDQR',
> 'SSPSDR',
> 'STSSER',
> ],
> [
> 'CSANLH',
> 'CVANRD',
> ],
> [...],
> ...,
> ];
> etc.
>
> I want these sorted first alphabetically within the group, and then
> according to the number of member in the group.
$ perl -le'
use Data::Dumper;
my $groups = [
[ qw/ STSSER SSPSDR SSPDQR / ],
[ qw/ CVANRD CSANLH / ],
];
print Dumper $groups;
my @s_groups = map $_->[ 1 ],
sort { $a->[ 0 ] <=> $b->[ 0 ] }
map [ scalar @$_, [ sort @$_ ] ],
@$groups;
print Dumper [EMAIL PROTECTED];
'
$VAR1 = [
[
'STSSER',
'SSPSDR',
'SSPDQR'
],
[
'CVANRD',
'CSANLH'
]
];
$VAR1 = [
[
'CSANLH',
'CVANRD'
],
[
'SSPDQR',
'SSPSDR',
'STSSER'
]
];
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/