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.
anarres: (Default)
Hmmm. It seems like it isn't possible on a Dreamhack to access a module in the ~/dw/cgi-bin/DW/Controller folder. This:

---------------------------------
#!/usr/bin/perl

use lib "$ENV{LJHOME}/cgi-bin";
use DW::Controller::Nav;
---------------------------------

produces this:

Name "Template::Filters::BASEARGS" used only once: possible typo at /usr/lib/perl5/Template/Base.pm line 49.
Name "Template::Context::BASEARGS" used only once: possible typo at /usr/lib/perl5/Template/Base.pm line 49.
Name "Template::BASEARGS" used only once: possible typo at /usr/lib/perl5/Template/Base.pm line 49.
Name "Template::Service::BASEARGS" used only once: possible typo at /usr/lib/perl5/Template/Base.pm line 49.
Name "Template::Provider::BASEARGS" used only once: possible typo at /usr/lib/perl5/Template/Base.pm line 49.
Name "Template::Plugins::BASEARGS" used only once: possible typo at /usr/lib/perl5/Template/Base.pm line 49.

and you get the same message if Nav is replaced with any other Controller module.

I could try to figure this out, or I could just work around it... I think I'm going to work around it :-)
anarres: (Default)
As part of getting ready for GSoC I've been reading about perl's DBI (database interface) module, which lets you interact with an SQL database through a perl script, rather than typing SQL into a terminal. There's a good little intro to it in Chapter 14 of the freely available Perl Cookbook from O'Reilly. (Free ebooks are one of my favourite things ever).

This script shows the simplest possible example of using DBI:

Read more... )

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

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 3rd, 2026 02:54 pm
Powered by Dreamwidth Studios