[Omaha.pm] silly warnings

Theodore Katseres tedkat at gmail.com
Mon Jan 19 14:39:26 PST 2009


On Mon, Jan 19, 2009 at 1:46 PM, Dan Linder <dan at linder.org> wrote:

> Just to follow-up on my previous e-mail, here are my results and a test
> case.
>
> I added the "no warnings qw(uninitialized)" jusst before my line 57, but
> left out the "use warnings qw(uninitialized)" as Jay suggested and it worked
> like a charm.
>
> In another section of code, I had similar warnings but that code called a
> few other subroutines.  I setup this code to test if the "no use warnings"
> would carry over to the subroutine:
>
> dan:/tmp$ cat d30.pl
> #!/usr/bin/perl
> use warnings;
> sub myfunc {
>   $f1 = 123;
> }
> $x = 10;
> for (1..1) {
>   no warnings;
>   $y = 10;
>   $funcreturn = myfunc();
> }
> $z = 10;
>
> dan:/tmp$ ./d30.pl
> Name "main::f1" used only once: possible typo at ./d30.pl line 6.
> Name "main::z" used only once: possible typo at ./d30.pl line 15.
> Name "main::x" used only once: possible typo at ./d30.pl line 9.
> dan at dglaptop:PerlTests$
>
> The "no warnings" does not carry out of the current block of code into the
> subroutine (I got the "main::f1 used only once").
>
> Thanks for the input everyone,


$f1 is not in the C<for> block. It is globally defined. ( wont compile with
C<use strict;> )

use C<my> for variable declarations.

#!/usr/bin/perl
use warnings;
sub myfunc {
  my $f1 = 123;

}
my $x = 10;
for (1..1) {
  no warnings;
  $y = 10;
  $funcreturn = myfunc();
}
my $z = 10;

Gives you a clean run.


-- 
Ted Katseres
     ||=O=||
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/omaha-pm/attachments/20090119/f956156d/attachment.html>


More information about the Omaha-pm mailing list