|Don't ask to ask, just ask|
Using "my" suppresses "Name used only once" warning?by Wysardry (Pilgrim)
|on Feb 02, 2003 at 22:33 UTC||Need Help??|
Wysardry has asked for the wisdom of the Perl Monks concerning the following question:
I was under the impression that using the strict pragma and declaring variables with my was a good thing.
However, I have found that using "my" actually prevents warnings about variable names that are used only once being displayed.
Compare the following code examples:-
The above code generates the following warning message (in an HTML comment):-
The above code generates no warnings - even if I change "my $blah = 1" to just "my $blah" thereby not even giving it a value.
I realise that any real variable name typos would most likely be caught if using strict with "my" because they show up as undeclared, but how can you catch variables that are declared and not used?
Also, is there a reliable way of making a Perl CGI program run in an "ultra pedantic" mode so that errors such as using a string as a number or vice versa are caught? (The above settings don't do that.)