SHARE
TWEET

Untitled

a guest Jul 21st, 2017 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $VAR1 = {
  2.           'max_childrensubtree' => '7',
  3.           'port' => '1984',
  4.           'user' => 'someuser',
  5.           'password' => 'somepw',
  6.           'max_width' => '20',
  7.           'host' => 'localhost',
  8.           'attrs' => {
  9.                        'subattr2' => 'cat',
  10.                        'topattr1' => 'cat',
  11.                        'subattr2_1' => 'pt',
  12.                        'subattr1' => 'rel'
  13.                      },
  14.           'max_descendants' => '1000'
  15.         };
  16.    
  17. (
  18.   a => {
  19.     'key1' => 'ok',
  20.     'key2' => 'hello'
  21.   }
  22. )
  23.    
  24. (
  25.   'key1' => 'ok',
  26.   'key2' => 'hello'
  27. )
  28.    
  29. #!/usr/bin/perl
  30. use utf8;
  31. use strict;
  32. use warnings;
  33.  
  34. use Data::Dumper;
  35.  
  36. my %ini = (
  37.         'params' => {
  38.                       'max_width' => '20',
  39.                       'max_childrensubtree' => '7',
  40.                       'max_descendants' => '1000'
  41.                     },
  42.         'attrs' => {
  43.                      'topattr1' => 'cat',
  44.                      'subattr1' => 'rel',
  45.                      'subattr2' => 'cat',
  46.                      'subattr2_1' => 'pt',
  47.                    },
  48.         'basex' => {
  49.                      'host' => 'localhost',
  50.                      'port' => '1984',
  51.                      'user' => 'someuser',
  52.                      'password' => 'somepw'
  53.                    }
  54. );
  55.  
  56. &_parse_ini(%ini);
  57.  
  58. sub _parse_ini {
  59.   my $ref = shift;
  60.  
  61.   foreach (('params', 'basex')) {
  62.     foreach my $k (keys %{$ref->{$_}}) {
  63.         $ref->{$k} = $ref->{$_}->{$k};
  64.     }
  65.     delete $ref->{$_};
  66.   }
  67.  
  68.   print Dumper($ref);
  69. }
  70.    
  71. #!/usr/bin/perl
  72. use utf8;
  73. use strict;
  74. use warnings;
  75.  
  76. use Data::Dumper;
  77. use Config::IniFiles;
  78.  
  79. # Load config file
  80. tie my %ini, 'Config::IniFiles', (-file => $ARGV[0]);
  81.  
  82. &_parse_ini(%ini);
  83.  
  84. sub _parse_ini {
  85.   my $ref = shift;
  86.  
  87.   foreach (('params', 'basex')) {
  88.     foreach my $k (keys %{$ref->{$_}}) {
  89.         $ref->{$k} = $ref->{$_}->{$k};
  90.     }
  91.     delete $ref->{$_};
  92.   }
  93.  
  94.   print Dumper($ref);
  95. }
  96.    
  97. [params]
  98. max_width = 20
  99. max_childrensubtree = 7
  100. max_descendants = 1000
  101.  
  102. [attrs]
  103. topattr1 = cat
  104. subattr1 = rel
  105. subattr2 = cat
  106. subattr2_1 = pt
  107.  
  108. [basex]
  109. host = localhost
  110. port = 1984
  111. user = admin
  112. password = admin
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top