host: http://www.yaoo.co.jp/
port: 80
users:
-
name: yourname
pass: yourpass
-
name: yourname1
pass: yourpass1
テストコードの内容
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use Encode;
use YAML::Syck;
use Data::Dumper;
my $yamlname = 'configs.yaml';
open my $fh, '<', $yamlname || die "filename : $!";
read $fh, my $input, (-s $yamlname);
close $fh;
$YAML::Syck::ImplicitTyping = 1;
my $configs = YAML::Syck::Load($input);
print Data::Dumper::Dumper($configs);
print YAML::Syck::Dump($configs);
print $configs->{host}, "\n";
for my $user (@{$configs->{users}}) {
print $user->{name}, "\n";
}
実行結果
$VAR1 = {
'port' => 80,
'host' => 'http://www.yahoo.co.jp/'
};
---
host: http://www.yahoo.co.jp/
port: 80
http://www.yahoo.co.jp/
yourname
yourname1