Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > list vs. array

Reply
Thread Tools

list vs. array

 
 
Robert Suyemoto
Guest
Posts: n/a
 
      09-25-2006
Hello.

I have recently heard the claim that in Perl,
"list" and "array" are two separate things, in that
one is of fixed length and the other isn't.

(Such that for the fixed length type, you could not
use push or pop on it.)

I have never heard of anything like this, but in
the interest of keeping an open mind, is there any
context where this would be true?


Thanks very much,
R.



 
Reply With Quote
 
 
 
 
David Squire
Guest
Posts: n/a
 
      09-25-2006
Robert Suyemoto wrote:
> Hello.
>
> I have recently heard the claim that in Perl,
> "list" and "array" are two separate things, in that
> one is of fixed length and the other isn't.
>
> (Such that for the fixed length type, you could not
> use push or pop on it.)
>
> I have never heard of anything like this,


Gee. You could have tried reading the documentation that comes with
Perl. When I type "perldoc -q list vs array", the third entry is
entitled "What is the difference between a list and an array?". The
first two sentences of that entry are "An array has a changeable length.
A list does not."

That is not the only difference. I suggest that you read the documentation.


DS
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      09-25-2006
Robert Suyemoto wrote:

> I have recently heard the claim


you mean the fact.

> that in Perl,
> "list" and "array" are two separate things, in that
> one is of fixed length and the other isn't.


One is a constant (or literal), one is a variable.

> (Such that for the fixed length type, you could not
> use push or pop on it.)
>
> I have never heard of anything like this, but in
> the interest of keeping an open mind, is there any
> context where this would be true?


This is a list: ('foo', 'bar', 'baz')
This is an array: @stuff;

An array is a variable that contains a list of scalars. It is (mostly)
analogous to the difference between a scalar value, like 'Hello World',
and the variable $phrase which might contain it. You can change
$phrase by concatenating to it or using a s/// operator, but you can't
change an actual literal string:

#this works, obviously:
$string =~ s/Hello/Goodbye/;
#but this gives "Can't modify constant item in substitution (s///) "
'Hello World' =~ s/Hello/Goodbye/;

Similarly,
#this works
push @stuff, 'bam';
#but this gives "Type of arg 1 to push must be array (not constant
item)"
push ('foo', 'bar', 'baz'), 'bam';


See also: perldoc -q difference
Found in /opt2/Perl5_8_4/lib/perl5/5.8.4/pod/perlfaq4.pod
What is the difference between a list and an array?

Paul Lalli

 
Reply With Quote
 
John Bokma
Guest
Posts: n/a
 
      09-25-2006
Robert Suyemoto <(E-Mail Removed)> wrote:

> Hello.
>
> I have recently heard the claim that in Perl,
> "list" and "array" are two separate things,


perldoc -q list


--
John Experienced Perl programmer: http://castleamber.com/

Perl help, tutorials, and examples: http://johnbokma.com/perl/
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      09-25-2006
>>>>> "PL" == Paul Lalli <(E-Mail Removed)> writes:

PL> Robert Suyemoto wrote:
>> I have recently heard the claim


PL> you mean the fact.

>> that in Perl,
>> "list" and "array" are two separate things, in that
>> one is of fixed length and the other isn't.


PL> One is a constant (or literal), one is a variable.

i would say a list is a value (could be generated from a func call or
expression) and an array is a variable which can hold a list.

other major points i use to explain this:

lists live on the stack and are live only during that expression.
arrays live on the heap (allocated) and can be alive as long as you want

list have no way to be referenced later
arrays can have references and be anonymous and used in data trees

lists can never have a name
arrays could have names

lists are fixed size since they are the result of an expression
arrays can have their size changed since they are in variables

lists and arrays can be indexed and sliced. this is about the only
operation common to both.

uri

--
Uri Guttman ------ http://www.velocityreviews.com/forums/(E-Mail Removed) -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
robb@acm.org
Guest
Posts: n/a
 
      09-25-2006

> i would say a list is a value (could be generated from a func call or
> expression) and an array is a variable which can hold a list.
>


Oy!

IMO, what a crazy distinction. Especially since the words 'array' and
'list' have meanings in the real world - for example, different kinds
of Abstract Data Types.

 
Reply With Quote
 
David Squire
Guest
Posts: n/a
 
      09-25-2006
(E-Mail Removed) wrote:
>> i would say a list is a value (could be generated from a func call or
>> expression) and an array is a variable which can hold a list.
>>

>
> Oy!
>
> IMO, what a crazy distinction. Especially since the words 'array' and
> 'list' have meanings in the real world - for example, different kinds
> of Abstract Data Types.
>


Oh for goodness sake! All programming languages give their reserved
words specific and restricted means compared to the usage of that word
in the "real world". Get used to it. There is a difference between a
Perl array and a Field Programmable Gate array too.

Ah you saying that the distinction between a string variable and a
string literal in almost every programming language is also "crazy"?

There is an important distinction between a variable and the values it
can represent?

'This is a string literal';
my $string; # this is a variable capable of representing a string
(amongst other things).


DS
 
Reply With Quote
 
robb@acm.org
Guest
Posts: n/a
 
      09-25-2006
David Squire wrote:
> Oh for goodness sake!




>
> Ah you saying that the distinction between a string variable and a
> string literal in almost every programming language is also "crazy"?
>


Not at all. Especially as you named them, respectively:
"string variable", and
"string literal".

But as soon as you'd call one a "string", and the other something like
"text block", then it gets suspicious.

Now applying (your!) naming logic (which I agree with), two names such
as:
"list variable", and
"list literal"...

would generate a guaranteed 10% reduction in pointless questions to
c.l.p.m.

 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      09-26-2006
(E-Mail Removed) <(E-Mail Removed)> wrote:


[ Please provide an attribution when you quote someone. ]


>> i would say a list is a value (could be generated from a func call or
>> expression) and an array is a variable which can hold a list.
>>

>
> Oy!
>
> IMO, what a crazy distinction.



But one that must be understood if you hope to understand Perl.

It can be crazy, and you can argue it if you like, but you still
need to make the distinction if you need to make sense of Perl.


> Especially since the words 'array' and
> 'list' have meanings in the real world -



And they have meanings in the Perl world.


> for example, different kinds
> of Abstract Data Types.



for example, data and a variable that can hold that kind of data.


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      09-26-2006
>>>>> "ro" == robb@acm org <(E-Mail Removed)> writes:

ro> Now applying (your!) naming logic (which I agree with), two names such
ro> as:
ro> "list variable", and
ro> "list literal"...

ro> would generate a guaranteed 10% reduction in pointless questions to
ro> c.l.p.m.

balderdash. people reading the docs would lower the pointless questions
to almost 0. computer stuff is about being exact in what you code and
that means exact in the meanings of terms. perl like all other projects
chose its names and terms and the key is to be consistant with them, not
to make them cater to those who don't care. if you want to hack perl you
talk perl. you don't talk cobol or python here. lists and arrays are
well defined in perl and they are not the same. did you even read the
differences i listed? did you understand how they are actually more
different than they are the same? do you understand the concept of a
value vs a variable (types don't matter)? string variable vs string
literal. the difference is variable vs literal and string doesn't
matter. list value and array variable. notice the differences there?
both terms are different so they both mean something. lists are not
variables nor arrays. arrays are not values (but they contain a value
and can supply that value to an expression).

learn perl and stop asking for perl to learn you.

uri

--
Uri Guttman ------ (E-Mail Removed) -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const and array of array (of array ...) Mara Guida C Programming 3 09-03-2009 07:54 AM
list of countries File v. Array v. HTML list slinky ASP .Net 1 06-18-2007 08:01 PM
length of an array in a struct in an array of structs in a struct in an array of structs Tuan Bui Perl Misc 14 07-29-2005 02:39 PM
array of char array in headerfile (string list) - some questions sigi C++ 4 07-03-2005 04:17 PM
Length of Array of Array of Array Tom Perl Misc 3 12-20-2004 05:23 PM



Advertisments