For example:
sub foo1 { my ($c, $d, $e, $f) = @_; return $d * f; } sub foo2 { my ($c, $d, $e, $f) = @_; return $c + $d + $e + $f; } sub do_foo { my $which = $_[0] ? \&foo1, \&foo2; $which->(1, 2, 3, 4); }
As you see foo1 uses only uses the second argument and fourth ($d, $f). But the assignment happens via my ($c, $d, $e, $f) = @_;. If a warnings is introduced for lexical variables that are used once then it will warn. (lexicals $c and $e are declared and initialized but never used.
Yes, the assignment could be changed into: my ($d, $f) = @_[1, 3]; but this would be worse from a maintenance point of view.
With my ($c, $d, $e, $f) = @_; you know exactly what parameters are passed (assuming they get a decent name). If you use my ($d, $f) = @_[1, 3]; then you are clueless about the other arguments.
If you later need the other arguments then you need to start looking in what order they were passed.
In reply to Re^4: Warnings on unused variables?
by Animator
in thread Warnings on unused variables?
by AZed
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |