in reply to Dynamic Dereferencing

# Convert a . to }->{ in order for meta.created to look like meta}->{created $element =~ s/\./}->{/g; # This works for all elements except of meta}->{created $deref = $item->{$element}; print "Convert: \$item->{" . $element . "}\t\t\t" . $deref . "\n"; }

I think you are trying to achieve something with a sort of "meta-coding" which is quite dangerous: when you write $item->{$element} you're try to access the hash $item value with a key like "...}->{..." which is why you then get that error, because there isn't such a key!

If you really want to do such a sort of meta-coding, then you need to write for instance  "$item->{".$element."}" and then you can try to eval() that thing. Why instead not trying one of the modules recommended by haukex ?

Replies are listed 'Best First'.
Re^2: Dynamic Dereferencing
by Anonymous Monk on Dec 07, 2018 at 12:25 UTC
    String eval is not to be used . especially not as a substitute for functions and loops for dereference

      ?

      I was replying to the OP on why he had that error and the only reasonable way to correct that code. I never recommended eval-ing concatenated strings as a good practice. The opposite as a matter of facts!

      Eval()-ing has, of course, its use cases, but as I said, it's dangerous in this particular case. One of the reasons of why I encouraged using some of the mentioned CPAN alternatives, if possible, to navigate nested structures.