http://qs321.pair.com?node_id=232066

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:-

#!/Perl/bin/perl -w use CGI::Carp qw(fatalsToBrowser warningsToBrowser); # use strict; use warnings; print "Content-type: text/html\n\n"; warningsToBrowser(1); $blah = 1; print "No problemo\n";

The above code generates the following warning message (in an HTML comment):-

warning: Name "main::blah" used only once: possible typo at c:\test\test.pl line 7.

#!/Perl/bin/perl -w use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use strict; use warnings; print "Content-type: text/html\n\n"; warningsToBrowser(1); my $blah = 1; print "No problemo\n";

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.)

__________
"Every program has at least one bug and can be shortened by at least one instruction -- from which, by induction, one can deduce that every program can be reduced to one instruction which doesn't work." -- (Author Unknown)