Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Building dynamic nested hash references

by BrowserUk (Patriarch)
on Jan 21, 2004 at 12:08 UTC ( [id://322853]=note: print w/replies, xml ) Need Help??


in reply to Building dynamic nested hash references

A short function to follow the path makes for a nice clean syntax.

#! perl -slw use strict; my $tree = { 'misc' => {}, 'docs' => { 'howtos' => { 'email' => { 'index.html' => { 'date' => '21-1-2004', 'size' => '691' } }, 'ftp' => {}, 'ssh' => {} } } }; sub find{ my( $href, $path ) = @_; $href = $href->{ $_ } for grep{ $_ } split '/', $path; $href; } my $input = '/docs/howtos/email/'; print find( $tree, $input )->{ 'index.html' }{ size };

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Timing (and a little luck) are everything!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-04-25 06:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found