Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: "Dynamically" Accessing a HoH

by monkey_boy (Priest)
on Jun 02, 2005 at 15:10 UTC ( [id://462947]=note: print w/replies, xml ) Need Help??


in reply to "Dynamically" Accessing a HoH


the 1st post would do it if you always only have two keys, if an unknown number of keys can be given try this...

#!/usr/bin/perl use strict; use warnings; my $usr_str = "{depTar}{name}"; my @keys = $usr_str =~ m/\{(.*?)\}/g; my $xml = { 'depTar' => { 'name' => 'c_p20', 'loc' => 'srvr1' }}; my $href = $xml; for my $i (0 .. $#keys) { $href = $href->{$keys[$i]}; }; print $href;



Update: fixed spelling mistake

This is not a Signature...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://462947]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (7)
As of 2024-04-24 10:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found