Perl: Difference Between List and Array

By Xah Lee. Date: . Last updated: .

What's the difference between list and array?

Lists in Perl are not data structures, they are positions in the source code, determined by the context around them. Lists are basically the transient structures that Perl uses to move data around. You interact with them with all of Perl's syntax, but you can not work with them as a data type. The data type that is closest to a list is an array.


here's a better detailed article: 〔perl array vs list By Michael Schwern. @〕. Quote:

in Perl, lists and arrays are not strictly the same thing. Though they will often be referred to interchangeably.

In internals sense an array is something that has a corresponding AV, which means that it can referenced and modified. A list is a temporary construct of an unmodifiable set of values on the stack.

Thus in the code

@foo = ( $a, $b, $c );

the left hand side of the = is an array, the right hand side is a list.

If you don't know Perl, you might go “huh?”. That's right. That's Perl.

that's what i call “lang underneath mumble jumble”. Many lang do the same, including Common Lisp, Python. It's just that it's a bit more severe in Perl.

What is “Language Underneath Mumble Jumble”?

often, these lang's documentation, syntax, semantics, have man-made complexity, but the fanatics defend it by speaking of certain “internal model”, or “objects” (as in what happens when the “compiler” read your code).

lang with undearneath mumble jumble do not focus on what programers need to do, nor how things are mathematically, but focus on what the compiler, implementation, hardware, engineering, do. Thus, for example, in Common Lisp communities, you'll see that lispers insist on what the word “list” means (to them, it's certain “linked list”, their “cons, car, cdr” 〔►see Fundamental Problems of Lisp〕), and outrageously deny common sense or other language's senses. In C/C++, there the term “array” has one very specific meaning, tied to hardware.

what langs don't have “underneath mumble jumble”? Answer: Mathematica, PHP.

for more examples of undearneath mumble jumble, see: