On Mon, Jul 09, 2001 at 04:48:42PM +0530, baby lakshmi wrote:
>
>
> Thank you for your mail.
> then can u tell me, what does the following line mean (this is from perl
> style)
>
> "To get the last element in a list or array, use $array[-1] instead of
> $array[$#array]. The former works on both lists and arrays, but the latter
> does not."
You can't use $#array on a list, since it doesn't have a name.
> Thank you
> REgards
> babylakshmi
> >From: Aaron Craig <[EMAIL PROTECTED]>
> >To: [EMAIL PROTECTED]
> >Subject: Re: diff bet list and an array
> >Date: Mon, 09 Jul 2001 13:08:58 +0200
> >
> >At 16:30 09.07.2001 +0530, baby lakshmi wrote:
> >>hi,
> >>What is the difference between list and an array??
> >>May be this very small question. but i would like to know the difference.
> >>The help in this regard is appreciated.
> >>Thank you
> >>Regards
> >>babylakshmi
> >
> >There isn't one.
Well, actuallly that's not quite right. There is quite a bit of
difference. See perlfaq4, copied here.
What is the difference between a list and an array?
An array has a changeable length. A list does not. An
array is something you can push or pop, while a list is a
set of values. Some people make the distinction that a
list is a value while an array is a variable. Subroutines
are passed and return lists, you put things into list
context, you initialize arrays with lists, and you
foreach() across a list. "@" variables are arrays,
anonymous arrays are arrays, arrays in scalar context
behave like the number of elements in them, subroutines
access their arguments through the array "@_", and
push/pop/shift only work on arrays.
As a side note, there's no such thing as a list in scalar
context. When you say
$scalar = (2, 5, 7, 9);
you're using the comma operator in scalar context, so it
uses the scalar comma operator. There never was a list
there at all! This causes the last value to be returned:
9.
--
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net