Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Re: problem with hash keys

by june_bo (Novice)
on Jun 17, 2001 at 07:25 UTC ( #89129=note: print w/replies, xml ) Need Help??

in reply to Re: problem with hash keys
in thread problem with hash keys

Thanks for all the good advice.
I need to keep the order for cosmetic reasons; the user will expect to see the end results (a bunch of sets) in the same order he entered them.
I have to use hashes because I do (what I think are) wonderful and amazing things with them later in the program.

Thanks again to everyone.

Replies are listed 'Best First'.
Re: Re: Re: problem with hash keys
by ariels (Curate) on Jun 17, 2001 at 15:34 UTC
    Then you can additionally store for each hash the order in which its keys are in:
    # ... push @grammar_keys, $1 unless exists $grammar{$1}; $grammar{$1} = $2; # ... print "$k\n" for my $k (@grammar_keys);
    (I've also taken the liberty of using lowercase variable names; you should probably use all-uppercase names only for special global variables).

    Or you can use a module like Tie::IxHash, which implements hashes with ordered keys just like you want.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2017-10-19 04:00 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (251 votes). Check out past polls.