gregw has asked for the wisdom of the Perl Monks concerning the following question:
I was expecting the database to get '2' but it was getting '1' because I had repeated the initialization and definition of the variable in the inner scope. Shame on me. I kept scrutinizing all my $usefuldata-related logic which turned out not to be the problem at all.local $usefuldata = undef; ... $usefuldata = 1; # in real life, lots of logic here ... if (blah blah) { local $usefuldata = undef; ... $usefuldata = 2; # in real life, lots of logic here ... } insert into database $usefuldata
OK, so I know why my bug happened. I even knew such bugs could happen. What I now want to know is, is there some useful trick or mechanism like 'use strict' or 'perl -w' that I could use to catch this class of bug more easily? Something that flags instances where I take a variable named my $x or local $x and create a new instance of $x in a different scope?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(Ovid) Re: Detecting scoping/namespace conflicts
by Ovid (Cardinal) on Apr 03, 2002 at 21:23 UTC | |
by Kanji (Parson) on Apr 03, 2002 at 22:20 UTC | |
by gregw (Beadle) on Apr 04, 2002 at 12:35 UTC | |
|
Re: Detecting scoping/namespace conflicts
by stephen (Priest) on Apr 03, 2002 at 22:10 UTC | |
|
Don't think so...
by RMGir (Prior) on Apr 04, 2002 at 13:06 UTC |