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

Re: Proposed pragma: readonly - summary

Thread Previous | Thread Next
From:
Ian Phillipps
Date:
May 22, 2000 04:08
Subject:
Re: Proposed pragma: readonly - summary
Message ID:
20000522113724.A4301@homer.diplex.co.uk
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
> http://www.xray.mpe.mpg.de/mailing-lists/modules/1999-02/msg00090.html
> 
> Mark-Jason Dominus pointed out his tie-based solution at
> http://www.plover.com/~mjd/perl/Locked/
> 
> 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";'
pi=3.14159
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.

Ian

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About