Skip to content

Instantly share code, notes, and snippets.

@smpb
Created September 13, 2012 14:51
Show Gist options
  • Save smpb/3714802 to your computer and use it in GitHub Desktop.
Save smpb/3714802 to your computer and use it in GitHub Desktop.
Perl hash-based config
{
author => 'sergio',
handle => 'smpb',
country => 'portugal',
complexity => {
number => 4,
depth => [ 'a', 'b', 'c' ]
}
}
#!perl
use 5.014;
use warnings;
use Data::Dumper;
open my $fh, '<', $ARGV[0];
my $contents = do { local $/; <$fh> };
close $fh;
my $config = eval $contents;
die "Config file did not return a hashref.\n"
unless ref $config && ref $config eq 'HASH';
foreach my $key (keys %{$config})
{
say "$key => $config->{$key}";
}
say Dumper $config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment