in reply to cgi input

No.

Also, your code will break on perl 5.8.1, which randomizes the output of hashes, even inside the same run of a program. Update: Untrue, as per merlyn's reply.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

: () { :|:& };:

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Random Hash Understandings (was Re: Re: cgi input)
by merlyn (Sage) on Nov 04, 2003 at 16:54 UTC
    Perhaps you misunderstand the "random hash change".

    A hash will always have an internal ordering. As long as you aren't adding new keys, the keys and their values can be accessed by any of: (1) hashname in a list context, (2) each(), (3) keys(), and (4) values(), and the lists will remain consistent.

    What got changed is how a given set of keys gets set into that order. Each time a new hash is created, a random value is associated with that hash, and it perturbs the hashing algorithm so that the ordering is mostly unpredictable.

    So, existing programs that call keys() and values() in parallel can still work. What won't work is expecting the same set of keys in a new hash to be the same order as an old hash.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Re: Re: cgi input
by jZed (Prior) on Nov 04, 2003 at 17:00 UTC
    The order of the hash is irrelevant. You end up with a list of keys, and you use that to get the values (see my answer below), the order of either keys or values doesn't make any difference.
      In your case the order is irrelevent, but isn't it nice to know that keys and values will be "synchronized" none the less? :)
      my %hash = qw(foo bar baz qux one two three four); my @key = keys %hash; my @val = values %hash; print "$key[$_] => $val[$_]\n" for 0..$#key;

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)