in reply to Calling splice() on Immutable Arrays
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Calling splice() on Immutable Arrays
by SankoR (Prior) on Jul 13, 2016 at 20:48 UTC | |
by BrowserUk (Patriarch) on Jul 13, 2016 at 23:21 UTC | |
by SankoR (Prior) on Jul 14, 2016 at 13:40 UTC | |
by BrowserUk (Patriarch) on Jul 14, 2016 at 18:13 UTC | |
by shmem (Chancellor) on Jul 15, 2016 at 09:49 UTC |