Re: constant
am 06.02.2006 19:04:27 von Paul LalliGeorge Bouras wrote:
> How do I know if a constant has been defined earlier ?
>
> use constant 't12' => 111;
>
> ...
>
> print 't12 defined' if What???
.... if defined &t12;
This is an illustration of why you should not use Perl's built-in
constant.pm pragma. A much better alternative is the Readonly module
available from CPAN:
http://search.cpan.org/~roode/Readonly-1.03/Readonly.pm
(The reason the above works is that constant.pm implements constants by
defining a sburoutine with that constant's name, so you're testing for
the defined'ness of that subroutine. Hence the &)
Paul Lalli