in reply to Constant string reference

There is a readonly subroutine in Scalar::Util that you can use to do this simply, or If you have Inline available you can do this yourself trivially:

use Inline C; + my $FOO = "Bar"; + readonly($FOO); + $FOO = "GG"; __DATA__ __C__ + void readonly(SV *sv) { SvREADONLY_on(sv); }

/J\

Replies are listed 'Best First'.
Re^2: Constant string reference
by Fletch (Bishop) on Dec 09, 2004 at 13:03 UTC

    Erm, Scalar::Util::readonly reports but doesn't set the readonly flag:

    readonly SCALAR Returns true if SCALAR is readonly. sub foo { readonly($_[0]) } $readonly = foo($bar); # false $readonly = foo(0); # true