develooper Front page | perl.perl5.porters | Postings from May 2000

Re: Proposed pragma: readonly - summary

Thread Previous | Thread Next
Ian Phillipps
May 22, 2000 04:08
Re: Proposed pragma: readonly - summary
Message ID:
On Sun, 21 May 2000 at 18:12:25 +0100, Mark Summerfield wrote:
> Several people have developed independent solutions to readonly
> variables which suggests to me that there is a requirement for them:

> Andreas pointed out Graham Barr's tie-based solution at
> Mark-Jason Dominus pointed out his tie-based solution at
> I pointed out my (old) tie-based solution (on my perl antiques page).

Hmm... I've always (well, since perl 5) done this:
	*pi = \3.14159;
You can then read $pi, but not alter it. No XS, modules or tying required.

~ % perl -we '*pi=\3.14159;print "pi=$pi\n"; $pi+=1; print "pi now $pi\n";'
Modification of a read-only value attempted at -e line 1.

I just did a Benchmark and the speed of reading is identical with a
"normal" global scalar.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About