Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: hashes

by jrsmith (Pilgrim)
on May 31, 2000 at 22:03 UTC ( #15668=note: print w/ replies, xml ) Need Help??


in reply to hashes

is it not a valid practice to specify the keys you want to print when looping through a hash like that? you seem to be surprised that i would do that, is there a better way? i think i may just forego the foreach altogether.. yes now that i think about it it's not really necessary as the hash will not be varying in size..


Comment on Re: hashes
RE: Re: hashes
by ZZamboni (Curate) on May 31, 2000 at 22:07 UTC
    The thing is, if you know which keys you want to process, and you want them in a specific order, there is no reason to use keys in the first place. Just give the keys in an array, as others have suggested, and index into the hash using them. keys is useful for getting all the keys in a hash, precisely so that you don't have to know their values in advance.

    --ZZamboni

      yeah i realize that now.. keys isn't really useful here.. but hey i wrote this script after maybe 2 or 3 weeks of teaching myself perl and now having had 2 whole months of experience i actually have learned a few things.. thanx :)
RE: Re: hashes
by nuance (Hermit) on May 31, 2000 at 22:09 UTC
    is it not a valid practice to specify the keys you want to print when looping through a hash like that?

    No, unfortunately you can't specify the order that keys will be returned, not using that method anyway. You can either use the keys function and sort its return value, or specify each of the keys in some other way, see posts above for examples

    Nuance

    Baldrick, you wouldn't see a subtle plan if it painted itself purple and danced naked on top of a harpsichord, singing "Subtle plans are here again!"

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2014-08-20 23:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (125 votes), past polls