Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: searching nested structures

by Anonymous Monk
on Jan 05, 2004 at 05:49 UTC ( [id://318792]=note: print w/replies, xml ) Need Help??


in reply to searching nested structures

One way to deal with autovivification is copying:

use Storable qw/dclone/; my $data = { test => { foo => { bar => 'bar', baz => 'baz', bul => { foo => { bar => 'bul' } } }, bar => { baz => 'baz' }, }, foo => { bar => 'foo' }, bar => [1,2,{foo => {bar => 42}},3] }; my @result = rec_data('->{foo}->{bar}',$data); print join(':',@result),"\n"; sub rec_data { my $path = shift; my $data = shift; my $ref = ref $data || return; my @vals = $ref eq 'HASH' ? values %$data : @$data; my $cdat = dclone($data); return (eval"\$cdat$path" || (),map{rec_data($path,$_)}@vals) }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 11:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found