constant

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

use constant 't12' => 111;

....

print 't12 defined' if What???
George Bouras [ Di, 07 Februar 2006 01:04 ] [ ID #1175562 ]

Re: constant

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
Paul Lalli [ Mo, 06 Februar 2006 19:04 ] [ ID #1175563 ]
Perl » alt.perl » constant

Vorheriges Thema: open3 STDERR blocking
Nächstes Thema: basic question help with strings