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

Re: Hashes Question

by jandrew (Hermit)
on Nov 30, 2012 at 23:36 UTC ( #1006537=note: print w/ replies, xml ) Need Help??


in reply to Hashes Question

As one of the potential (and newer) 'Walk' module authors you might find on CPAN this a trimmed Synopsis for Data::Walk::Graft

#!perl use Modern::Perl; use Moose::Util qw( with_traits ); use Data::Walk::Extracted 0.017; use Data::Walk::Graft 0.011; use Data::Walk::Print 0.013; my $gardener = with_traits( 'Data::Walk::Extracted', ( 'Data::Walk::Graft', 'Data::Walk::Clone', 'Data::Walk::Print', ), )->new( sorted_nodes =>{ HASH => 1, },# For demonstration consistency graft_memory => 1, ); my $tree_ref = { Helping =>{ KeyTwo => 'A New Value', KeyThree => 'Another Value', OtherKey => 'Something', }, MyArray =>[ 'ValueOne', 'ValueTwo', 'ValueThree', ], }; $gardener->graft_data( scion_ref =>{ Helping =>{ OtherKey => 'Otherthing', }, MyArray =>[ 'IGNORE', { What => 'Chicken_Butt!', }, 'IGNORE', 'IGNORE', 'ValueFive', ], }, tree_ref => $tree_ref, ); $gardener->print_data( $tree_ref ); print "Now a list of -" . $gardener->number_of_scions . "- grafted positions\n"; $gardener->print_data( $gardener->get_grafted_positions ); ############################################################ # Output of SYNOPSIS # 01 { # 02 Helping => { # 03 KeyThree => 'Another Value', # 04 KeyTwo => 'A New Value', # 05 OtherKey => 'Otherthing', # 06 }, # 07 MyArray => [ # 08 'ValueOne', # 09 { # 10 What => 'Chicken_Butt!', # 11 }, # 12 'ValueThree', # 13 , # 14 'ValueFive', # 15 ], # 16 }, # 17 Now a list of -3- grafted positions # 18 [ # 19 { # 20 Helping => { # 21 OtherKey => 'Otherthing', # 22 }, # 23 }, # 24 { # 25 MyArray => [ # 26 , # 27 { # 28 What => 'Chicken_Butt!', # 29 }, # 30 ], # 31 }, # 32 { # 33 MyArray => [ # 34 , # 35 , # 36 , # 37 , # 38 'ValueFive', # 39 ], # 40 }, # 41 ], ############################################################

It is still in development but the API shouldn't change substantially. Feel free to use the module or leverage the source to your preference.


Comment on Re: Hashes Question
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2014-09-02 20:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (29 votes), past polls