It sounds to me like this is not a job for Perl's sort function at all (despite the impressions of the original poster and most of those who have replied so far).
It looks to me like you just want to "sort" the items into bins, not really "sort" them into a specific order.
I might well switch from @data to %data since I suspect it would be difficult to keep type numbers strictly sequential.my @data; while( <DATA> ) { chomp; my( $num, $name )= split /\s*,\s*/, $_, 1; push @{$data[$num]}, $name; } my $num= 0; for my $byNum ( @data ) { for my $name ( @$byNum ) { print "$num,$name\n"; } $num++; }
If you do want to sort within each numbered group, then simply add:
- tyefor my $byNum ( @data ) { @$byNum= sort @$byNum; }
In reply to Re: 2 dimensional array sorting... (no sort)
by tye
in thread 2 dimensional array sorting...
by Soko
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |