#!/usr/bin/perl -w
##
## sutechy@sutechy.com [~/www]# ./p_arrayref.pl
## Massachussetts: Boston, Quincy, Waltham.
## Rhode Island: Bristol, Providence, Warren.
##
## sutechy@sutechy.com [~/www]# cat zipcode
## Providence, Rhode Island
## Bristol, Rhode Island
## Warren, Rhode Island
## Boston, Massachussetts
## Waltham, Massachussetts
## Quincy, Massachussetts
##
##
use strict;
my %table;
my $file = "zipcode";
open(FILE, "<$file") or die "UNABLE TO OPEN $file: $!\n";
while(){
chomp;
my ($city, $state) = split(/,/, $_);
$table{$state} = [] unless exists $table{$state};
push @{$table{$state}}, $city;
}
close(FILE);
for my $state (sort keys %table) {
print "$state: ";
my @cities = @{$table{$state}};
print join ', ', sort @cities;
print ".\n";
}