[ create a new paste ] login | about

Link: http://codepad.org/8fJG5XaB    [ raw code | output | fork ]

vol7ron - Perl, pasted on Oct 12:
use Data::Dumper;

   my $foo = "a:b:c:d:a";
   my $bar = "a:b:c:d:z";
   my $hoh = {};
   sub createHash {
      my ($hoh,$orig,$rest,$last) = @_;
      $rest = $rest || $orig;
      $_ = $rest;
      if (/^(.*?):(.*)$/)
      { 
         $hoh->{$1} = $hoh->{$1} || {};
         createHash($hoh->{$1},$orig,$2,$1);
      } 
      elsif (defined($last)) 
      {
         push (@{$hoh->{value}} , [$rest,$orig]);
      }
      return $hoh;
   }
   $hoh = createHash($hoh,$foo,undef);
   $hoh = createHash($hoh,$bar,undef);

   print Dumper($hoh);


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$VAR1 = {
          'a' => {
                   'b' => {
                            'c' => {
                                     'd' => {
                                              'value' => [
                                                           [
                                                             'a',
                                                             'a:b:c:d:a'
                                                           ],
                                                           [
                                                             'z',
                                                             'a:b:c:d:z'
                                                           ]
                                                         ]
                                            }
                                   }
                          }
                 }
        };


Create a new paste based on this one


Comments: