http://www.perlmonks.org?node_id=462940

Nitrox has asked for the wisdom of the Perl Monks concerning the following question:

I have a HoH whose keys are unknown at "programming time" (The structure is returned from XML::Simple after parsing an XML file), and I also have a "user string" that is passed at runtime which is a "text representation" of the value the user is looking to have returned.

I have a working PoC below which utilizes eval and I'm looking for feedback on whether I'm overlooking a way to achieve the same results without using eval.

#!/usr/bin/perl use strict; use warnings; my $usr_str = "{depTar}{name}"; my $xml = { 'depTar' => { 'name' => 'c_p20', 'loc' => 'srvr1' }}; my $dyn = '$xml->' . "$usr_str"; print eval $dyn;