Section 6.3. YAML


6.3. YAML

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.

From the earlier example, we plug in YAML where we had Data::Dumper, and use Dump( ) where we had Dumper( ).

 use YAML; my %total_bytes; while (<>) {         my ($source, $destination, $bytes) = split;         $total_bytes{$source}{$destination} += $bytes;         } print Dump(\%total_bytes); 

When you use the same data from the earlier example, you get this output:

 --- #YAML:1.0 ginger.girl.hut:   maryann.girl.hut: 199   professor.hut: 1218 professor.hut:   gilligan.crew.hut: 1250   lovey.howell.hut: 1360 thurston.howell.hut:   lovey.howell.hut: 1250 

That's a lot easier to read because it takes up less space on the screen, which can be really handy when you have deeply nested data structures.




Intermediate Perl
Intermediate Perl
ISBN: 0596102062
EAN: 2147483647
Year: N/A
Pages: 238

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net