even though the container is immutable
It isn't. It looks like splice doesn't care about SvREADONLY at all (but unshift does). You can extend such a list an array via splice:
@a = qw[a simple list]; warn join ' ', @a; # "a simple list" Internals::SvREADONLY(@a, 1); # Make the list RO (doesn't matter he +re, actually) Internals::SvREADONLY($a[1], 1); # Make our target element RO (double +sure!) warn '@a is ' . (Internals::SvREADONLY(@a) ? '' : 'not ') . 'read-only +'; splice(@a, 1, 1, qw(not quite readonly)); warn join ' ', @a; # "a not quite readonly list" warn '@a is ' . (Internals::SvREADONLY(@a) ? '' : 'not ') . 'read-only +'; unshift @a, qw*this is*; __END__ a simple list at 1167665-reply.pl line 2. @a is read-only at 1167665-reply.pl line 5. a not quite readonly list at 1167665-reply.pl line 7. @a is read-only at 1167665-reply.pl line 8. Modification of a read-only value attempted at 1167665-reply.pl line 9 +.
This is a bug (incomplete implementation, maybe also a design issue). It looks like Internals::SvREADONLY has been tacked onto, not "bolted through" the perl source
In reply to Re: Calling splice() on Immutable Arrays
by shmem
in thread Calling splice() on Immutable Arrays
by SankoR
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |