Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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..

Replies are listed 'Best First'.
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.


      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


    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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://15668]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2018-02-18 01:58 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (250 votes). Check out past polls.