YAML

Aug. 11th, 2010 07:59 am
anarres: (Default)
YAML is a "human-readable data serialization format", according to Wikipedia. Apparently it's terribly flexible and powerful. But I just want to make a simple configuration file to use with a Perl script. I worked out how to do this with help from Stackoverflow (I love Stackoverflow). Super-simple example:

test.yaml:

---
image_width: 1000
show_values: 0


test.pl:

#!/usr/bin/perl

use strict;
use warnings;
use 5.010;

use YAML qw(LoadFile);

my $settings = LoadFile('test.yaml');
say "The image width is ", $settings->{image_width};


You can also go backwards: starting from the Perl code version of the configuration data you want, you can generate the YAML file:

make_yaml.pl

use strict;
use warnings;

use YAML;

my %settings = (
foo => 1,
bar => [qw/one two three/],
);

print Dump(\%settings);


Hmmm, funny how the Stackoverflow people assume I'm a "he" though.

Profile

anarres: (Default)
anarres

July 2012

S M T W T F S
1234567
891011121314
151617 18192021
222324 25262728
293031    

Syndicate

RSS Atom

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 10th, 2025 11:06 pm
Powered by Dreamwidth Studios