in reply to redefining Internals::SvREADONLY

Are there other methods to circumvent data that has been marked read-only?

The readonly flag can be turned off.

Replies are listed 'Best First'.
Re^2: redefining Internals::SvREADONLY
by ChiefAl (Initiate) on May 05, 2010 at 23:23 UTC

    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?

      "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.