Useless use of private variable in void context (Perl)

by Thomas Beutel

Can you see what is wrong with this Perl code snippet?

foreach my $cat (@$categories) {
if ($cat->{col} == $column and $cat=>{pos} == $position) {
return $cat;
}
}

It gets the “Useless use of private variable in void context” at the last brace. Well, it took me a while, but it was the equal sign in $cat=>{pos} which should be $cat->{pos}. Worse, I copied and pasted this code somewhere else, which doubled the problem. (Yes I know, all copying and pasting is evil–I get it!)

In any case, this comment on Perlmonks was helpful, suggesting to look for typos backward from the point of the error. Yup, that’s exactly what it was.