Thinking about it, I'd rather see lvalue slices become a nicer version
of C<splice()>.
my @start = (0..5);
my @a = @start;
@a[1..3] = qw/ a b c d e /;
print @a; # 0 a b c d e 4 5
# Similarly:
@a = @start;
my $r_slice = [EMAIL PROTECTED];
@$r_slice = qw/ a b c d e /;
print @a; # 0 a b c d e 4 5
# Note that it does NOT modify in rvalue context
print reverse @$r_slice; # e d c b a
print @a; # 0 a b c d e 4 5
# To modify, do this:
@$r_slice = reverse @$r_slice;
print @a; # 0 e d c b a 4 5
As far as what happens when you modify the array to which the slice
points--treat it like any other reference. If you undef an array to
which you are holding a reference, the reference is suddenly reffing a
null array. If you undef an array slice to which you are holding a
reference, your slice ref is now reffing undef.
@a = @start;
$r_slice = [EMAIL PROTECTED];
print @a; # 0 1 2 3 4 5
print @$r_slice; # 0 1 2 3
shift @a; # (*)
print @a; # 1 2 3 4 5
print @$r_slice; # 1 2 3
(*) There should probably be a suppressable warning emitted here,
something like:
"Warning: slice reference being modified" or
"Warning: slice reference such-and-such included this element; ref modified"
If slices DO get this functionality, it would be nice to add a method
whereby we could retrieve the min/max keys (for an array) or the set
of keys (for a hash) which they are currently reffing.
--Dks