roho has asked for the wisdom of the Perl Monks concerning the following question:
I just finished tracking down a very elusive bug in my code. The bug was caused by two defined's side by side (a copy/paste error). Perl doesn't object at either compile time or at run time, but two defined's reverses the logic of the expression. In the sample code below the first "if" statement is False (as expected), but the second "if" statement is True because of the two defined's.
I suppose there may be a use case somewhere where the result of one "defined" is fed into another, but my first reaction was that this is a bug. What do other monks think about this? Is this a bug in Perl or a "feature"?
#!/usr/bin/perl use strict; use warnings; my $x; if (defined $x) { print "True\n"; } else { print "False\n"; } if (defined defined $x) { print "True\n"; } else { print "False\n"; }
"Its not how hard you work, its how much you get done."
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: defined defined -- Bug or "Feature"?
by dave_the_m (Monsignor) on Dec 24, 2015 at 07:45 UTC | |
by GrandFather (Saint) on Dec 24, 2015 at 08:00 UTC | |
by dave_the_m (Monsignor) on Dec 24, 2015 at 09:33 UTC | |
by Anonymous Monk on Dec 24, 2015 at 09:29 UTC | |
Re: defined defined -- Bug or "Feature"?
by GrandFather (Saint) on Dec 24, 2015 at 07:56 UTC | |
by Anonymous Monk on Dec 24, 2015 at 08:33 UTC | |
by dave_the_m (Monsignor) on Dec 24, 2015 at 09:36 UTC | |
by Anonymous Monk on Dec 24, 2015 at 10:21 UTC | |
Re: defined defined -- Bug or "Feature"?
by dsheroh (Monsignor) on Dec 24, 2015 at 08:39 UTC | |
Re: defined defined -- Bug or "Feature"?
by Anonymous Monk on Dec 24, 2015 at 10:23 UTC |
Back to
Seekers of Perl Wisdom