Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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.


In reply to Re: Hashes Question by jandrew
in thread Hashes Question by anshumangoyal

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (5)
    As of 2015-07-04 10:15 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (59 votes), past polls