Chinaunix首页 | 论坛 | 博客
  • 博客访问: 855385
  • 博文数量: 253
  • 博客积分: 6891
  • 博客等级: 准将
  • 技术积分: 2502
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-03 11:01
文章分类

全部博文(253)

文章存档

2016年(4)

2013年(3)

2012年(32)

2011年(184)

2010年(30)

分类: Python/Ruby

2011-10-24 10:04:31

Data::Dumper is not the only game on the island, though. Brian Ingerson came up with Yet Another Markup Language (YAML) to provide a more readable (and more compact) dump. It works in the same way as Data::Dumper. We'll see more about YAML when we talk about modules later, so we won't say much about it here.

  1. use YAML;

  2. my %total_bytes;

  3. while (<>) {
  4.         my ($source, $destination, $bytes) = split;
  5.         $total_bytes{$source}{$destination} += $bytes;
  6.         }

  7. print Dump(\%total_bytes);
  1. --- #YAML:1.0
  2. ginger.girl.hut:
  3.   maryann.girl.hut: 199
  4.   professor.hut: 1218
  5. professor.hut:
  6.   gilligan.crew.hut: 1250
  7.   lovey.howell.hut: 1360
  8. thurston.howell.hut:
  9.   lovey.howell.hut: 1250
阅读(950) | 评论(0) | 转发(0) |
0

上一篇:Data::Dumper

下一篇:use Storable

给主人留下些什么吧!~~