in reply to Efficient partial deep cloning
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 :-)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)
|
|---|