No question here! Just want to show some code.
$systems = { 'xai61001' => { # ref to hash ip => '192.168.1.1' , name => 'xai61001', model => '8205_E6C', }, 'xai61002' => { # ref to hash name => 'xai61002', model => '9119_MME', ip => '192.168.1.2' , }, }; $merge = { 'xai61001' => { # ref to hash description => 'Dit is een test voor xai61001', ibm_description => 'IBM system power 8 xai61001', }, 'xai61002' => { # ref to hash description => 'Dit is een test voor xai61002', ibm_description => 'IBM system power 8 xai61002', }, }; #Most examples I've found on the internet are speaking about "normal" +hashes!! #Wanted to be able to process a scalar pointing to a hash. # this is perl5 , Not perl6. Yes still struggling with it's syntax!! ##################################################################### # sliceAndDice a ref to a hash, in the end you can determine the order + in which a hash is displayed!! # I created 2 arrays which have the same order. Could be expensive whe +n processing a large hash_ref. # $sys = 'xai61002'; # entrie of the $systems HASH! print "$systems->{$sys}\n"; # HASH(0xnumber} print "$systems->{$sys}{ip}\n"; # ip address @keys = ( qw/ip name model/ ); # hardcoded the order of the keys!! print keys %{$systems->{$sys}},"\n"; # the normal way to get at the k +eys @values = @{$systems->{$sys}}{@keys} ; # getting the at the values, i +n the order of @keys # the above is processing a hash ( looks like an A +RRAY, but is NOT ) #print @keys, @values,"\n"; print "\n\nOriginal hash_ref\n"; for $idx ( 0 .. $#keys ) { print "$keys[$idx] => $values[$idx]\n"; } # adding some keys and values, please notice : This is adding to a has +h!! (which is a scalar reference) # the keys in $systems and $merge must be THE SAME $systems->{$key} $m +erge->{$key} !!, but the reference keys MUST be different # otherwise the merge will overwrite an existing key!! @merge = ( qw/description ibm_description/ ); @{$systems->{$sys}}{ @merge } = ( $merge->{$sys}{$merge[0]} , $merge-> +{$sys}{$merge[1]}); @keys = ( qw/description ip name model ibm_description/ ); @values = @{$systems->{$sys}}{@keys} ; #print @keys, @values,"\n"; print "\n\nAdded some keys and values: showing all items\n"; for $idx ( 0 .. $#keys ) { print "$keys[$idx] => $values[$idx]\n"; }

hope it's usefull to somebody!!


In reply to Slice and dice a ref to hash by teun-arno

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, 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.