"Luke Palmer" <[EMAIL PROTECTED]> wrote:
> Benjamin Goldberg wrote:
> > David Storrs wrote:
> > >      @a[1..3] = qw/ a b c d e /;
> > >      print @a;   #  0 a b c d e 4 5
> >
> > What would happen if I used 1,2,3 instead of 1..3?  Would it do the same
> > thing?
>
> Of course.

I tend to agree, I think. But see below

> > I wanna know what happens if I do:
> >
> >        @a[0,2,4] = qw/ a b c d e /;
>
> It would probably do the same as in Perl 5; the same thing as:
>
>     @a[0,2,4] = << a b c >>;

But that would be awful:

   @a[$x,$y] = <<a b c d e>>

would insert all 5 elements if ($y == $x+1); but only the first two
otherwise. Belch.

If we wanted the array-splice thing to resize arrays for us, then either we
trigger the behavior only when rx/ \[ <scalar> \.\. <scalar> \]/, or we need
to define the spilling algorithm in a way that makes sense (e.g. all
remaining items go into the element of the righmost index).

But perhaps there's a better way to beet the desire. Perhaps ellipses could
be emplyed to indicate that the splice is allowed to resize the array:

  @a[1...3] = qw(a b c d e);


Dave.


Reply via email to