Why wont 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/12 15:44 UTC
Read the original article Hit count: 331

Filed under:
|
|

Why wont 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

Related posts about perl

Related posts about sorting