in reply to Alphanumeric sort
Please close your code tags properly and separate it into paragraphs as needed. Show us some sample code as well as your desired result for your sample data. The below is a good starting point
chomp(my @unsorted = (<DATA>)); my @sorted = sort { $a cmp $b } @unsorted; say for @sorted; __DATA__ 1208782,abc 406744,def 367455,abc 283191,mps 226159,abc 197688,rxwz 137875,rxwz 115901,abc 107297,def 99213,mps
If I understand you correctly though, you just want to sum the numeric values associated with each alphanumeric code. If this is the case, you don't necessarily need to sort them. You can simple track sums into a hash.
use Data::Dump qw(pp); chomp(my @lines = (<DATA>)); my $sums = {}; for my $line (@lines) { my ($num,$let) = split ',', $line; $sums->{$let} += $num; } say pp($sums);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Alphanumeric sort
by zac_carl (Acolyte) on Sep 20, 2011 at 18:13 UTC | |
by Kc12349 (Monk) on Sep 20, 2011 at 20:01 UTC | |
by Marshall (Canon) on Sep 20, 2011 at 20:50 UTC |