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

Re: Proposed pragma: readonly - summary

Mark Summerfield
May 22, 2000 12:22
Re: Proposed pragma: readonly - summary
Message ID:

Tom Christiansen wrote:
> >       const $READONLY = 99 ; # OR use readonly '$READONLY' => 99 ;
> >       *MYREADONLY = \'splat!' ;
> >       print $READONLY ; # Yep, prints "splat!" and no warnings
> >Looks like you can't have genuinely readonly scalars in perl unless you
> >use ties...
> Why should this be an issue?  Just because you can't diddle $foo doesn't
> mean you can't diddle the *foo typeglob.

Its not that I don't want to be able to mess with *foo - that's useful;
it is just that I really want to have constants that will stay that way
and still can't find a good way of doing it.

> Coming soon from a Larry near you:
>     At some point, we'll enable the use of a C<constant> attribute
>     on variable declarations:
>         my $PI : constant = 4 * atan2(1,1);
>     This has all the advantages of being a variable rather than a
>     subroutine.  It has all the disadvantages of not being implemented yet.
> --tom

That's good news to me. Over the years all my perl 'annoyances' have
evaporated as I learnt more, except for not being able to have decent
constants. (Although new ones have come along of course:)

The first thing I'd like to be able to do is export my constants...
which I can't do with my's. I feel that constants do need to be
exportable to be fully useful. (See my reply to Ian Phillipps,
following, for a note on that.)

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