I don't know how this compares against a string eval (probably depends on how deep the structure is), but if the path is stored as something like qw(A 2 H foo H bar A 1), then you could traverse down a path like so (untested, unthought out rough idea):
my @path = qw( A 2 H foo H bar A 1 ); my $data = [ "foo", "bar", { foo => { bar => [ 5, 6, ], }, }, ]; while ( @path ) { my $type = shift @path; my $index = shift @path; if ( $type eq 'A' ) { $data = $data->[$index]; } else { $data = $data->{$index}; } } print $data; # prints "6" (I hope)
Of course, if you want to assign to something in the path, you'd have to traverse the path up until the last item, then assign, etc. Ehh, I'm not sure if or when this might be more efficient or any better than the eval method, but there it is :-)

In reply to Re: Efficient partial deep cloning by runrig
in thread Efficient partial deep cloning by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.