加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl引用的实例

发布时间:2020-12-16 00:32:50 所属栏目:大数据 来源:网络整理
导读:$ 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?@{

$ cat country
Chicago,USA
Frankfurt,Germany
Berlin,Germany
Washington,USA
Helsinki,Finland
New York,USA

?

 
 
  1. #!/usr/bin/perl?-w?
  2. use?strict;?
  3. my?%table;?
  4. my?($city,$country);?
  5. while?(<>)?{?
  6. ?chomp;?
  7. ?my?($city,$country)?=?split?/,/;?
  8. ?push?@{$table{$country}},$city;?
  9. }?
  10. ?
  11. foreach?$country?(sort?keys?%table){?
  12. ?print?"$country:";?
  13. ?my?@cities?=?@{$table{$country}};?
  14. ?print?join?',',?sort?@cities;?
  15. ?print?".n";?
  16. ?
  17. }?
  18. ?

result:

$ perl country.pl country ?Finland:Helsinki. ?Germany:Berlin,Frankfurt. ?USA:Chicago,New York,Washington.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读