ispsh 发表于 2018-8-31 12:32:06

perl引用的实例

  $ cat country
  
Chicago, 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]
查看完整版本: perl引用的实例