in reply to Problem with symbolic deferencing into XML::Simple's internal representation of an XML file.

I think you are confused about symbolic references.

# reference the parameter directly. Prints Jane's number print "ref1 = ", $config->{jane}->{tel_no}, "\n";
This tells me that $config->{jane}->{tel_no} probably contains some string mostly containing digits and punctuation.
# construct the same symbolic reference locally # just to make sure. Still yields nothing! $parm_str = "\$" . "config->{jane}->{tel_no}, "\n"; print "ref3 = ", $$parm_str, "\n";
Well, first I'll assume you really meant:     $parm_str = "\$" . $config->{jane}->{tel_no}; which does not set $parm_str to be a symbolic reference. A symbolic reference is when $parm_str contains the name (and only the name) of a global variable and you write $$parm_str to access the named global variable.

I don't think you have any global variables named '$(800)4345-6789'. Note that if you had a global variable that you accessed as $foo, then its name would be "foo" and not '$foo' (or even '\\$foo').

Also, the value $config->{jane}->{tel_no} is almost certainly not stored in any global variable, so symbolic references can't be used to access that data.

Perhaps you want non-symbolic references (often called "real" references or "hard" references). Then you'd use:     $parm_str = \$config->{jane}->{tel_no}; But I'd need more description about what you are trying to do before I could say whether that would help you or not.

Also note that you don't set a variable to some special value to make it a symbolic reference. A symbolic reference happens when you dereference something that isn't a hard reference. Intentional (potential) symbolic references are just simple strings that happen to match the name of some global variable. So it isn't until you try to dereference it that strict can tag it as a symbolic reference.

Or perhaps you meant to do something like:     $parm_str = '$config->{jane}->{tel_no}'; in which case you'd "dereference" that using eval:     print "value = ", eval($parm_str), "\n"; which I wouldn't suggest is a good idea. Perhaps you are trying to do this because you can't figure out how to get to "jane"'s "tel_no" in cases when you don't know how many levels deep you'll need to go. If so, then this has been discussed a couple of times before so let us know and we can point you to those discussions (if you can't locate them yourself).

        - tye (but my friends call me "Tye")
  • Comment on (tye)Re: Problem with symbolic deferencing into XML::Simple's internal representation of an XML file.
  • Select or Download Code