[Omaha.pm] silly warnings
Jay Hannah
jay at jays.net
Sat Jan 17 08:50:59 PST 2009
On Jan 15, 2009, at 1:18 PM, Dan Linder wrote:
> From this site URL: http://www.xav.com/perl/lib/Pod/perllexwarn.html
> Looks like I need to wrapper line 55 like this:
>
> 55 } else {
> 56 ($value, $parm)=split(/\s+/,$line,2);
> no warnings qw(uninitialized);
> 57 $myhash1{$section_name}{$parm} = $value;
> use warnings qw(uninitialized);
> 58 }
Line 57 has 4 moving parts, any of which will throw a warning if
things aren't kosher.
- Is %myhash1 guaranteed to be defined?
- Is $section_name guaranteed to be defined?
- Is $parm guaranteed to be defined?
- Is $value guaranteed to be defined?
If not, and you care, then you'd need to add code to guarantee that
those values are defined once line 57 happens.
Also, it looks like "no warnings" only effects the block you're in,
so you can safely omit the "use warnings" line. It'll get put back
automatically, as I demo below. :)
Cheers,
j
$ cat j.pl
use warnings;
$x = 10;
for (1..1) {
no warnings;
$y = 10;
}
$z = 10;
$ perl j.pl
Name "main::z" used only once: possible typo at j.pl line 8.
Name "main::x" used only once: possible typo at j.pl line 3.
More information about the Omaha-pm
mailing list