in reply to There is a way to LOCK a SCALAR?

Update: As sauoq++ and duff++ point out, my brain was in neutral:(

The are several ways of approximating it, but the easiest to really create a simple, readonly scalar is Scalar::Util::readonly().

It is even part of the standard distribution in the most recent versions.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!

Replies are listed 'Best First'.
Re: Re: There is a way to LOCK a SCALAR?
by sauoq (Abbot) on Dec 18, 2003 at 19:49 UTC

    How will that help? Scalar::Util::readonly() is for checking whether a scalar is readonly, not for creating a readonly scalar.

    I'd second the method that Zaxo suggests in his update. That's the "old-fashioned" way to create constants. Here's how to use Scalar::Util::readonly() to prove it works nicely...

    perl -MScalar::Util=readonly -le '*f = \"foo"; print readonly($f)' 8388608

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: Re: There is a way to LOCK a SCALAR?
by duff (Parson) on Dec 18, 2003 at 19:49 UTC

    Doesn't Scalar::Util::readonly() just tell you if the scalar is readonly or not? I.e., you can't create a readonly scalar from it.