> -----Original Message-----
> From: Stephen P. Potter [mailto:[EMAIL PROTECTED]]
> Sent: Friday, September 07, 2001 1:37 PM
> To: Bob Showalter
> Cc: '[EMAIL PROTECTED]'; [EMAIL PROTECTED]
> Subject: Re: foreach and the ordering of array's
>
>
> Lightning flashed, thunder crashed and Bob Showalter
> <Bob_Showalter@taylorwhite
> .com> whispered:
> | One way to supply a list to for/foreach is to use the
> keys() function
> | to retrieve a list of the keys in a hash. keys() does not return the
> | key values in any particular order, due to the internal
> representation
> | of a hash.
>
> I think you are still a little confused. Try this:
No, I am not at all confused.
>
> perl -e '%x = qw/a b c d e f g h i j l k/; print keys %x,
> "\n"; print keys
> %x, "\n";'
>
> You should see that both print() print exactly the same
> thing, showing that
> keys() returns the same list both times. In other words, it
> is possible to
> predict what order keys() will return. It just may not be
> the order you
> might normally think (alphabetic, or numeric).
In other words "no particular order". As I said. I never said
or implied random or unpredictable order. Just not a typically
useful order.
>
> | But you want to supply an array to for/foreach. In that case, the
> | elements of the array are supplied in the array index
> sequence, which is
> | what you are looking for. This holds for any list context
> where an array
> | is used, not just for/foreach (e.g. print(), join(), map(), etc.)
>
> No, you want to supply a list to foreach, not an array. If
> you rewrite the
> above using a list for most everywhere you say array, you see how much
> simpler it is.
No, I meant what I wrote. The OP ("you") wanted to supply an *array*
to for/foreach and questioned the order.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]