oxone has asked for the wisdom of the Perl Monks concerning the following question:
This must be run with taint checking on in order to see the issue, so for this example, save as test.pl and run as follows with a numeric argument passed in, eg:use strict; use warnings; my $tainted = shift; my $test; $test = undef; $test += $tainted; print "Test 1: $test\n"; $test = undef; $test += $tainted; print "Test 2: $test\n";
Now, as I understand it, a '+=' op is allowed on an undefined value, so I'd expect this to work fine and to leave $test with a value of 1 in each case. However, the surprising thing is, this triggers a warning because $test is undefined, but ONLY the second time round after it has first been set with a tainted value and then undefined. So here's what happens:perl -T test.pl 1
I tested this on 2 different Perls, both with same result:%perl -T test.pl 1 Test 1: 1 Use of uninitialized value in addition (+) at test.pl line 12. Test 2: 1
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Inconsistent warnings over undefined values
by ysth (Canon) on Jan 19, 2009 at 10:46 UTC | |
by oxone (Friar) on Jan 19, 2009 at 13:55 UTC | |
A reply falls below the community's threshold of quality. You may see it by logging in. |