For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > February 2006 > constant









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author constant
George Bouras

2006-02-08, 6:57 pm

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

use constant 't12' => 111;

....

print 't12 defined' if What???
Paul Lalli

2006-02-08, 6:57 pm

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

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com