generate.pl 532 B

123456789101112131415161718192021222324252627282930313233
  1. use warnings;
  2. my %config;
  3. sub add_config {
  4. my ($prefix, $c) = @_;
  5. foreach my $key (keys $c) {
  6. my $val = $c->{$key};
  7. if (ref($val) eq 'HASH') {
  8. add_config($key . '.', $val);
  9. }
  10. elsif (ref($val) eq 'ARRAY') {
  11. $config{'@' . $prefix . $key . '@'} = join ' ', map {s/'/'\\''/g; "'" . $_ . "'"} @{$val}
  12. }
  13. unless (ref($val)) {
  14. $config{'@' . $prefix . $key . '@'} = $val;
  15. }
  16. }
  17. }
  18. add_config('', $CONFIG);
  19. my $regex = join '|', map {quotemeta} keys %config;
  20. for (<>) {
  21. s/($regex)/${config{$1}}/g;
  22. print;
  23. }