How to disable warnings?

Viewed 299

I have warning:

"my" variable $subject masks earlier declaration in same scope at ...

I know that I can disable warning via no warnings 'all' pragma, but can not find right category for my type of warnings.

How to disable only this type of warning?

3 Answers

Search perldoc perldiag for your warning message. This one turns up

"%s" variable &%s masks earlier declaration in same %s

(W shadow) A "my", "our" or "state" variable has been redeclared in the current scope or statement, effectively eliminating all access to the previous instance. This is almost always a typographical error. Note that the earlier variable will still exist until the end of the scope or until all closure references to it are destroyed.

which tells you that the pragma to disable this specific warning is

no warnings 'shadow';

How to disable only this type of warning?

Please don't do that. It's a far better idea to fix the bug that is causing the error.

You've declared $subject twice. Either remove the my from the second declaration or change the name of the second variable. I know nothing about your code, so I can't advise you on which approach is best.

Honestly, I wouldn't disable warnings at all. There is a good reason that they warn you about that. I would suggest that you look at how to prevent the warning and not deactivate them. If you want, post the code and let other people help you!

Related