Why doesn't this Perl array sort work?
Posted
by Luke
on Stack Overflow
See other posts from Stack Overflow
or by Luke
Published on 2010-05-12T15:35:39Z
Indexed on
2010/05/16
0:00 UTC
Read the original article
Hit count: 363
Why won't the array sort?
CODE
my @data = ('PJ RER Apts to Share|PROVIDENCE',
'PJ RER Apts to Share|JOHNSTON',
'PJ RER Apts to Share|JOHNSTON',
'PJ RER Apts to Share|JOHNSTON',
'PJ RER Condo|WEST WARWICK',
'PJ RER Condo|WARWICK');
foreach my $line (@data) {
$count = @data;
chomp($line);
@fields = split(/\|/,$line);
if ($fields[0] eq "PJ RER Apts to Share"){
@city = "\u\L$fields[1]";
@city_sort = sort (@city);
print "@city_sort","\n";
}
}
print "$count","\n";
OUTPUT
Providence
Johnston
Johnston
Johnston
6
© Stack Overflow or respective owner