in reply to Re: redefining Internals::SvREADONLY
in thread redefining Internals::SvREADONLY

do you mean there are other core subroutines which disable the readonly flag on a particular variable or is this a global option supplied by a switch?

Replies are listed 'Best First'.
Re^3: redefining Internals::SvREADONLY
by ikegami (Patriarch) on May 06, 2010 at 00:01 UTC

    "Other"? Ah, I didn't realize Internals::SvREADONLY could. Yes, it just exports SvREADONLY_on(sv) and SvREADONLY_off(sv) to Perl land.

    It sounds like you are trying to prevent someone from preventing you from making variables read-only. All I pointed out that it's moot since they can undo your work should you manage to get it done.

    But you know what, one doesn't even need to make the variable not readonly to change it. The READONLY flag is purely advisory. It can simply be ignored.

    use strict; use warnings; use Inline C => <<'__EOI__'; void change_it(SV* sv) { SvIV_set(sv, 789); SvIOK_only(sv); } __EOI__ my $i = 123; Internals::SvREADONLY($i, 1); print("$i\n"); eval { $i = 456; }; print("$i\n"); change_it($i); print("$i\n");
    123 123 789

    Update: Added realisation that READONLY if advisory.