Home > Archive > PERL Beginners > December 2006 > How do I tell perl -w: "I really want to use this var just once"
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How do I tell perl -w: "I really want to use this var just once"
|
|
| Kelly Jones 2006-12-18, 9:59 pm |
| perl -w dings me if I use a variable just once:
Name "main::foo" used only once: possible typo...
even if I'm magically defining/using $foo somewhere else.
Is there any way to tag a variable to tell the -w option that I'm
intentionally using that variable just once, and not to warn me about it?
I realize I could do something like: "$foo = $foo" to force the issue,
but that seems kludgy.
--
We're just a Bunch Of Regular Guys, a collective group that's trying
to understand and assimilate technology. We feel that resistance to
new ideas and technology is unwise and ultimately futile.
| |
| usenet@DavidFilmer.com 2006-12-18, 9:59 pm |
| Kelly Jones wrote:
> perl -w dings me if I use a variable just once:
First of all, you should 'use warnings', not 'perl -w'.
Second, you should always (in every program you write, no matter how
trivial)
use strict;
which will force you to properly declare/scope your variables, such as
my $foo = 'bar';
And, one nice side effect of using this proper coding style is that the
problem you are having will magically go away.
--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)
| |
| D. Bolliger 2006-12-18, 9:59 pm |
| Kelly Jones am Dienstag, 19. Dezember 2006 01:49:
> perl -w dings me if I use a variable just once:
>
> Name "main::foo" used only once: possible typo...
>
> even if I'm magically defining/using $foo somewhere else.
>
> Is there any way to tag a variable to tell the -w option that I'm
> intentionally using that variable just once, and not to warn me about it?
>
> I realize I could do something like: "$foo = $foo" to force the issue,
> but that seems kludgy.
Is it really not possible to
use warings;
use strict; # <-- your friend!
my $foo=1; # <-- declare lexical var with 'my'
print $foo; # prints 1
?
Then use
use warnings;
{
no warnings 'once';
$foo=1;
}
print $foo; # prints 1
Dani
|
|
|
|
|