in reply to (tye)Re2: Trying to pass a hash of hash of lists
in thread Trying to pass a hash of hash of lists

Otherwise we'd have to update a ton of documentation and do s/list/list or array/.

No, whenever a list is wanted, an array can be used because arrays evaluate to lists in list context. An array can be "downgraded" to list, but a list can never be an array without explicitly creating an array (either through the anonymous array reference constructors ([]) or an array assignment).

There are places where it is important to distinguish "arrays" from "lists" but perllol.pod is not such a place.

Of all places, perllol should know better. It's a very technical document, that serves as a tutorial for many people. It's important not to confuse beginners (and experts). String and number are converted on the fly in Perl, but saying that Foo is a number is wrong: it's a strings that evaluates to a number (0) in numeric scalar context (which can only be created by numeric operators). You can use a string as if it were a number, and you can use a number as if it were a string, but numbers and strings will never really be the same. You can use an array as if it were a list, (not the other way around, ) but arrays are not lists.

I could rant at how wrong you are for using "array" when you can't put an array in an array.

And right you would be.


A reference can evaluate to a number. A reference can evaluate to a string. But you can't reverse that: ${ "SCALAR(0x80fd338)" } will never be a real dereference.

When you have @foo = @bar, @bar is evaluated in list context, and the individual elements are assigned to the new array. That is because the syntax for an array assignment is not ARRAY = ARRAY, but ARRAY = LIST. That's also why copies are made.

scalar (numeric -- string -- boolean)list
undef0 -- "" -- false-
number123 -- "123" -- 0 ? false : true-
string0 -- "foo" -- "" or "0" ? false : true-
reference255 -- "TYPE(0xFF)" -- true-
arraynumber of elementsthe elements themselves
listlast elementthe elements themselves
hashnumber of keysa list of keys and values (interleaved)
Array and list are not the same thing, but you can evaluate arrays in list context ("convert" them).

U28geW91IGNhbiBhbGwgcm90MTMgY
W5kIHBhY2soKS4gQnV0IGRvIHlvdS
ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
geW91IHNlZSBpdD8gIC0tIEp1ZXJk

  • Comment on Re: (tye)Re2: Trying to pass a hash of hash of lists