On Aug 9, 10:39 am, [EMAIL PROTECTED] wrote:
> ----- Original Message -----
> From: Paul Lalli <[EMAIL PROTECTED]>
> Date: Thursday, August 9, 2007 8:52 am
> Subject: Re: slices
> To: [EMAIL PROTECTED]
>
> > $ perl -wle'my @bar = qw/alpha beta gamma/;  @bar[()] = (1, 2, 3);
>
>                                                                             
> ^^^^^^^
>
> Can you explain this?  The index is not intuitive to me.

It's an empty array slice.  A "normal" array slice would be something
like:

@bar[2, 3, 6] = ('foo', 'bar', 'baz');

which assigns foo, bar, and baz to the third, fourth and seventh
elements of @bar (respectively).  It's exactly the same as:
($bar[2], $bar[3], $bar[6]) = ('foo', 'bar', 'baz');

That is, @bar[2, 3, 6] represents a list containing the third, fourth,
and seventh elements of @bar.

Saying @bar[2] is a one-element array slice.  It is a list containing
only a single element - the third element of @bar.

@bar[()] is a zero-element array slice.  It is a list containing
nothing.  There is no point in ever using such a thing - I merely
posted it to illustrate my disagreement with John's assertion that a
slice requires more than one index.

Paul Lalli


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to