in reply to Warning messages about useless constants ignore '0's and '1's

From the source (op.c):
case OP_CONST: sv = cSVOPo_sv; if (cSVOPo->op_private & OPpCONST_STRICT) no_bareword_allowed(o); else { if (ckWARN(WARN_VOID)) { useless = "a constant"; /* don't warn on optimised away booleans, eg * use constant Foo, 5; Foo || print; */ if (cSVOPo->op_private & OPpCONST_SHORTCIRCUIT) useless = 0; /* the constants 0 and 1 are permitted as they are conventionally used as dummies in constructs like 1 while some_condition_with_side_effects; */ else if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0)) useless = 0;
Basically, if you use 0 and or 1 and, etc., Perl won't warn about the useless use of a constant.
_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Re: Warning messages about useless constants ignore '0's and '1's
by ysth (Canon) on May 11, 2004 at 03:53 UTC
    It will never warn about 0 or 1 in void context (including in a "list" specified in scalar context), and also will not warn about any constant on the left side of a short-circuiting op. You seem to have conflated the two cases.