develooper Front page | perl.perl5.porters | Postings from February 2004

Useless use of a constant in void context, when a constant is undef

Thread Next
From:
Stas Bekman
Date:
February 24, 2004 14:03
Subject:
Useless use of a constant in void context, when a constant is undef
Message ID:
403BCA0A.3040700@stason.org
Something weird happens if a constant gets an undef value and then used inside 
to define a lexical which is then used in the conditional. Consider this code:

#/tmp/constants
use strict;
use warnings;

use constant CONST => eval { require notthere } && 1;
#use constant CONST => undef;

my $switch = 0;
$switch++ if CONST;
$switch-- if $switch;

/tmp> perl /tmp/constant
Useless use of a constant in void context at /tmp/constant line 8.

   use constant CONST => undef;

has the same (bad) effect.

   use constant CONST => 0;

works just fine.

I have had this problem trying to do:

use constant IS_MOD_PERL_2_BUILD =>
     eval { require mod_perl && $mod_perl::VERSION >= 1.99 } &&
     require Apache::Build && Apache::Build::IS_MOD_PERL_BUILD();

which gets an 'undef' when eval fails. so undef comes from:

   use constant CONST => eval { die } && 1;


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About