2013-09-28 16:39:32 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
|
|
|
|
my %config;
|
|
|
|
|
|
|
|
sub add_config {
|
|
|
|
my ($prefix, $c) = @_;
|
|
|
|
|
|
|
|
foreach my $key (keys $c) {
|
|
|
|
my $val = $c->{$key};
|
|
|
|
|
2013-09-30 15:13:13 +00:00
|
|
|
if (ref($val) eq 'HASH') {
|
2013-09-28 16:39:32 +00:00
|
|
|
add_config($key . '.', $val);
|
|
|
|
}
|
2013-09-30 15:13:13 +00:00
|
|
|
unless (ref($val)) {
|
2013-09-28 16:39:32 +00:00
|
|
|
$config{'@' . $prefix . $key . '@'} = $val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub read_config {
|
|
|
|
my $input = shift;
|
|
|
|
my $CONFIG = do $input;
|
|
|
|
add_config('', $CONFIG);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-29 12:44:17 +00:00
|
|
|
read_config 'site/site.conf';
|
2013-09-28 16:39:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
my $regex = join '|', map {quotemeta} keys %config;
|
|
|
|
|
|
|
|
|
|
|
|
for (<>) {
|
|
|
|
s/($regex)/${config{$1}}/g;
|
|
|
|
print;
|
|
|
|
}
|