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

Re: Printing a hash in a specific order?

by fruiture (Curate)
on Mar 15, 2003 at 15:13 UTC ( #243296=note: print w/ replies, xml ) Need Help??


in reply to Printing a hash in a specific order?

A Hash does not have any order by definition. You speak of "template hash output that I am unaware of", and that can't imply a certain order of the hash keys. You can only generalize by sorting the keys lexically (or however), not "ordering". Your example _knows_ the hash it outputs and provides they keys to be output with their values. A "generic" way can only be generic, a hash is 'generically' without order (actually there is an order that depends on the way the hash is hashed).

Data::Dumper is a "generic" way of outputting various data structues ;)

--
http://fruiture.de


Comment on Re: Printing a hash in a specific order?
Re: Re: Printing a hash in a specific order?
by Limbic~Region (Chancellor) on Mar 15, 2003 at 15:23 UTC
    fruiture,
    I am not looking for a way to store the hash in a specific order. In my post, I acknowledged that hash keys do not come out in the order they are created. I was looking for a way to have the output automatically sorted (via some magic such as artist provided) into a pre-determined format when it came out un-ordered. Thanks for mentioning Data::Dumper - it made me think of something. I may be able to use it if I decide to stay with a hash and not start over.

    Cheers - L~R

      I was looking for a way to have the output automatically sorted [...] into a pre-determined format when it came out un-ordered.

      that's sort then. It depends on what your "pre-determined format" means.(?) I was confused by your example because it dictated the keys to be output in some order (just as the example output displayed no generic order but some specific one) and that's of course impossible to be done generically unless you specify this order without enumarating it. So we end up with sort() or some Hash-tying module that actually stores order of insertion (as you've been pointed to).

      --
      http://fruiture.de

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2014-07-30 02:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls