Why does Perl complain "Useless use of a constant in void context", but only sometimes? -
here perl script , output:
use strict; use warnings; (undef, 1); # no output (0, 1); # no output (1, 1); # no output (2, 1); # "useless use of constant in void context @ c:\...\void.pl line 7" (3, 1); # "useless use of constant in void context @ c:\...\void.pl line 8" ("", 1); # "useless use of constant in void context @ c:\...\void.pl line 9" ("0", 1); # "useless use of constant in void context @ c:\...\void.pl line 10" ("1", 1); # "useless use of constant in void context @ c:\...\void.pl line 11" i expect warnings @ every line. special undef, 0 , 1 causes not happen?
documented in perldoc perldiag complete rationale:
this warning not issued numerical constants equal
0or1since used in statements like1 while sub_with_side_effects();
as undef, it's function has uses in void context. e.g. undef($x) similar —but different than— $x = undef();. (you want latter.) warning issued uses of undef without args in void context, require specialized code, , it's not needed.
Comments
Post a Comment