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:

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

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

-spp
--
Stephen P Potter        Columbus, Ohio, USA              [EMAIL PROTECTED]
"You can't just magically invoke Larry and expect that to prove your point.
Or prove that you have a point."        -Simon Cozens
UNIX, Perl, PHP, Web Consulting and Training  http://www.unixlabs.net/~spp/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to