The following code will generate a warning. (The reason is because you need to wrap the 1,2,3
in parens).
$ perl -wE'my @foo = 1,2,3;'
Useless use of a constant (2) in void context at -e line 1.
Useless use of a constant (3) in void context at -e line 1.
But this code will not generate a warning,
$ perl -wE'sub foo {1}; sub bar {2}; sub baz {3}; my @foo = foo(), bar(), baz();
That seems awkward to me. While it seems reasonable to execute foo()
and baz()
in void context, that doesn’t seem useful or like something that should be encouraged. If nothing else, you would think when warnings are enabled catching the problem above would be ideal.
Is there a reason why this warning doesn’t exist?