Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: "Dynamically" Accessing a HoH

by monkey_boy (Priest)
on Jun 02, 2005 at 15:10 UTC ( #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? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (None)
    As of 2021-10-16 23:42 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My first memorable Perl project was:







      Results (70 votes). Check out past polls.

      Notices?