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 0 or 1 since used in statements like

1 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

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -