There are two questions here.
- Why
use bigint; 1; use bigint; 1; warns in a void context? - Why is a constant executed in the void context in the first place?
$ perl -c -we'1 while sub_with_side_effects();' -e syntax OK $ perl -c -we'use bigint; 1 while sub_with_side_effects();' Useless use of a constant (1) in void context at -e line 1. -e syntax OK
Why use bigint; 1; use bigint; 1; warns in a void context?
use bigint; sets the callback called when the parser encounters a constant literal, and the value returned by the callback is used instead of a constant. Thus, under use bigint; , 1 no longer just just 0 or 1 .
But you are not doing anything wrong, so this warning is false. You can get around this using () or undef instead of 1 .
undef while sub_with_side_effects();
If I do not need to use it in my code base, I would prefer the following:
while ( sub_with_side_effects() ) { }
$ cat Module.pm package Module; use bigint; 1; $ perl -c -w Module.pm Useless use of a constant (1) in void context at Module.pm line 3. Module.pm syntax OK
Why is a constant executed in a void context?
When Perl executes a module, Perl expects the module to return a scalar value, so Perl should execute the module in a scalar context.
However, you told Perl to compile script Module.pm . When Perl runs the script, Perl does not require any values to be returned, so Perl runs the script in the void context.
Using the module as a script can cause false warnings and errors, and therefore -W may pass. Check the module as follows:
perl -we'use Module'
In fact, you do not even need -W , since the module should already have use warnings; . All you really need is
perl -e'use Module'