Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: storing values of hash of hashes in an array based on numerical order of second key

by LanX (Saint)
on Aug 17, 2020 at 21:43 UTC ( [id://11120855]=note: print w/replies, xml ) Need Help??


in reply to storing values of hash of hashes in an array based on numerical order of second key

Dive into the hash of hashes with two nested while each loops and populate a temporary array.

Print the array's content afterwards.

If the data is in reality more sparse, populate a hash and sort the keys before printing the table.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

  • Comment on Re: storing values of hash of hashes in an array based on numerical order of second key

Replies are listed 'Best First'.
Re^2: storing values of hash of hashes in an array based on numerical order of second key
by perlfan (Vicar) on Aug 18, 2020 at 04:34 UTC
    each is basically evil. Don't use it.

    The iterator used by each is attached to the hash or array, and is shared between all iteration operations applied to the same hash or array. Thus all uses of each on a single hash or array advance the same iterator location. All uses of each are also subject to having the iterator reset by any use of keys or values on the same hash or array, or by the hash (but not array) being referenced in list context. This makes each-based loops quite fragile: it is easy to arrive at such a loop with the iterator already part way through the object, or to accidentally clobber the iterator state during execution of the loop body. It's easy enough to explicitly reset the iterator before starting a loop, but there is no way to insulate the iterator state used by a loop from the iterator state used by anything else that might execute during the loop body. To avoid these problems, use a foreach loop rather than while-each.
    
      I'm aware, but in this case there is no potential effect at a distance.

      We just loop without calling a sub routine and sharing the hash.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

Log In?
Username:
Password:

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

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

    No recent polls found