in reply to Need some help building a data structure.
1 use Data::Dumper; 2 use feature 'say'; 3 4 my $hashref; 5 my $code; 6 while(my $line = <DATA>) { 7 chomp $line; 8 my @pieces = split ':',$line; 9 my $val = pop @pieces; 10 $code .= ('$hashref'.join '',map { "->{'$_'}" }@pieces)."='$va +l';\n"; 11 }; 12 eval $code; 13 14 print Dumper $hashref; 15 16 __DATA__ 17 globalkey:key2:key3:key4:ARRAY VALUE 18 globalkey:key2:key3:key4:key5:ARRAY VALUE 19 globalkey:key2:key3:key4:key5:any arbitrary number of keys:ARRAY V +ALUE $VAR1 = { 'globalkey' => { 'key2' => { 'key3' => { 'key4' => 'ARRAY VA +LUE' } } } };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Need some help building a data structure.
by Anonymous Monk on May 02, 2009 at 07:33 UTC | |
by spx2 (Deacon) on May 02, 2009 at 07:53 UTC | |
by Anonymous Monk on May 02, 2009 at 08:08 UTC | |
by Anonymous Monk on May 02, 2009 at 08:17 UTC |