First off, the code I am attaching is not pretty, and there may well be a LOT better way of doing this, but I hope I am at least on the right track.

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*)

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)); }
The code I used to test was:

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

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.