Re: constant

Re: constant

am 06.02.2006 19:04:27 von Paul Lalli

George 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

constant

am 07.02.2006 01:04:16 von George Bouras

How do I know if a constant has been defined earlier ?

use constant 't12' => 111;

....

print 't12 defined' if What???