At 04:11 PM 8/22/00 -0400, John Porter wrote:
>Casey R. Tweten wrote:
> >
> > There is no documentation that states:
> >
> > ``keys() just doesn't work on lists and/or arrays,
>
>Why should it bother saying that, when it already says keys() works on a 
>HASH?
>
>Or is there some confusion that a HASH might also be an ARRAY or a LIST?

I can see that...

Perhaps part of the problem is:

@array1 = (1, 1, 3, 5, 8, 13);
%hash1  = ('foo', 34, 'bar', "not a number", 'baz', 4);
@array2 = %hash1;
%hash2  = @array1;

This works, and may lead to confusion because:

1) You can assign lists, arrays, and hashes to @array
2) You can assign lists, arrays, and hashes to %hash
3) @array and %hash in list context  works as expected
4) @array and %hash in array context works as expected
5) @array and %hash in hash context  works as expected

While lists won't work in array or hash contexts, there are few places 
where array or hash context is required, so a beginning Perl programmer 
might not bump into them except for keys(), values(), and similar.

It doesn't help that Camel II's glossary defines "array" as "A named list 
of values, each of which has a unique key to identify it.  In a normal 
array, the key is numeric... In a hash...the key is a string." and seems to 
go to a lot of effort to deprecate "array" in favor of "list" (array 
context: "A quaint, archaic expression used by people who have read the 
first edition of this book.  Nowadays called 'list context'.").

Reading that, what would you say the difference between an array, a list, 
and a hash is?

(My answer:  From that glossary, I'd say that 'array' and 'list' are 
virtually synonymous.  From actual use, I'd say that an array can be an 
lvalue, but a list is strictly an rvalue.)



>--
>John Porter
>
>         We're building the house of the future together.

Reply via email to