In article <[EMAIL PROTECTED]>, Steve Grazzini wrote:
> On Tue, Jul 01, 2003 at 11:40:55AM +0200, Kevin Pfeiffer wrote:
>> I tried a couple more variations - and wonder why the last
>> one doesn't evaluate a count of the slice...
>
> I think this is interesting:
>
>> $string = @array[0..1];
>> print "$string\n";
>> # prints "oranges" (why not "2"?)
>
> Do you expect the slice to return "2" because it looks
> like an array (and that's what an array would do) ?
> Or do you think $string should be "2" because there are
> two elements in the list ?
In preparation for a possible answer ("how to admit ignorance in a
knowledgeable mannner") I went to perldoc and found the question(s), the
answer(s) and more (thanks, though, to all here who also contributed):
Found in /usr/lib/perl5/5.8.0/pod/perlfaq4.pod
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 con�
text, 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 num�
ber of elements in them, subroutines access their argu�
ments 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:
So being a list is a little like being in purgatory - you're neither a
scalar nor an array (yet)? ;-)
--
Kevin Pfeiffer
International University Bremen
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]