Created
November 6, 2013 07:20
-
-
Save bessarabov/7332229 to your computer and use it in GitHub Desktop.
Исходный код Perl задачки http://perltrap.com/ru/konfiguracionnye-faily/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
parallel-level: 4 | |
timeout: 50 | |
verbose: 0 | |
port: 10018 | |
locale: UTF-8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
package Config; | |
use YAML; | |
sub load | |
{ | |
my ($class, %param) = @_; | |
my $conf; | |
if ( $param{file} =~ /\.yaml$/ ){ | |
print $param{file}."\n"; | |
$conf->{data} = YAML::LoadFile( $param{file} ); | |
$conf->{format} = "yaml"; | |
$conf->{file} = $param{file}; | |
} else { | |
die "unsupported format of config, stop"; | |
} | |
return bless $conf; | |
} | |
sub write | |
{ | |
my ($self, %param) = @_; | |
YAML::DumpFile($param{file}, $self->{data}); | |
return; | |
} | |
sub get | |
{ | |
my ($self, $key) = @_; | |
return $self->{data}->{$key}; | |
} | |
sub set | |
{ | |
my ($self, $key, $value) = @_; | |
$self->{data}->{$key} = $value; | |
return; | |
} | |
1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Config; | |
my $conf = Config->load(file => "conf.yaml"); | |
my $parallel_level = $conf->get("parallel-level"); | |
$conf->set("parallel-level", $parallel_level * 2); | |
$conf->write(file => "conf2.yaml"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment