in reply to Need some help building a data structure.

hmm, I wonder why this doesn't work ?
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
    Because you're using eval dangerously
    globalkey:'.`rm -rf /`.':fooled:you: now you data is gone
      you're right , but here it should have worked fine
        You sure? :)
        1 use Data::Dumper; 2 use feature 'say'; String found where operator expected at - line 2, near "use feature 's +ay'" (Do you need to predeclare use?) 3 ^Z "use" not allowed in expression at - line 1, near "1 " syntax error at - line 1, near "1 use Data::Dumper" "use" not allowed in expression at - line 2, near "2 " Execution of - aborted due to compilation errors.