perl引用的实例
$ cat countryChicago, USA
Frankfurt, Germany
Berlin, Germany
Washington, USA
Helsinki, Finland
New York, USA
[*]#!/usr/bin/perl -w
[*]use strict;
[*]my %table;
[*]my ($city,$country);
[*]while () {
[*] chomp;
[*] my ($city,$country) = split /,/;
[*] push @{$table{$country}},$city;
[*]}
[*]
[*]foreach $country (sort keys %table){
[*] print "$country:";
[*] my @cities = @{$table{$country}};
[*] print join ',', sort @cities;
[*] print ".\n";
[*]
[*]}
[*]
result:
$ perl country.pl country
Finland:Helsinki.
Germany:Berlin,Frankfurt.
USA:Chicago,New York,Washington.
页:
[1]