Also, I noticed in your code, you referenced tel_no, but the XML file has tel_num... I will assume tel_num is correct. I also noticed the following was probably a typo:
$parm_str = "\$" . "config->{jane}->{tel_no}, "\n"; $parm_str = '$config->{jane}->{tel_no}';
as the string "config->{jane}->{tel_no}" was not correctly terminated. Anyway, here is my first pass, please let me know if this helps/does not help. (I whimped out and used recursion. *Smiles*)
The code I used to test was:package xmlutil; #-- Use modules use strict; use XML::Simple; #-- Define constants use constant DEBUG => 1; use constant DELIM => ','; use constant XMLFILE => './galaxy.xml'; #-- Define global variables my $gConfig = XMLin(XMLFILE); #-- This is the sub which is used to interface to the #-- main perl code. Had to do this as the C program does not #-- know $gConfig sub get_ival { #-- Get parameter my $pParm=shift; #-- Return the value print get_ivnode(\$gConfig,$pParm); } #-- This is the sub which recursively processes the XML hash array sub get_ivnode { #-- Get parameters my $pPtr=shift; my @pParm = split(DELIM,shift); #-- Define local variables my $lKey; my $lNewPtr; #-- Get the next key $lKey=shift(@pParm); #-- Display debugging information print '[',$lKey,']',"\n" if DEBUG; #-- Return the value if there are no further keys return $$pPtr unless $lKey; #-- Build the new pointer $lNewPtr=$$pPtr->{$lKey}; #-- Call with next node return get_ivnode(\$lNewPtr,join(DELIM,@pParm)); }
use strict; use lib '/temp'; use xmlutil; xmlutil::get_ival('jane,tel_num');
Notice this "solution" requires you to change how you are calling the perl code -- instead of building the "perlish" string, you list the hierarchy separated by commas.
Am I off base here, or is this what you wanted?
Update:
Might want to change the following line so the recursive sub is called one time fewer.
return $$pPtr unless $lKey; return $$pPtr->{$lKey} unless $pParm[0];
In reply to Re: Problem with symbolic deferencing into XML::Simple's internal representation of an XML file.
by Rhose
in thread Problem with symbolic deferencing into XML::Simple's internal representation of an XML file.
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |