breeze has asked for the wisdom of the Perl Monks concerning the following question:
I have a code:
#!/usr/bin/perl use utf8; use warnings; use strict; my $var1; my $var2 = "0"; my $var3 = 0; my $var4 = "a"; print isDef($var1)."\n"; print isDef($var2)."\n"; print isDef($var3)."\n"; print isDef($var4)."\n"; sub isDef { if (shift) { return "true"; } else { return "false"; } }
The result of execution is:
./test.pl false false false true
The first variable is really undefined, but why second & third is undefined too?
p.s. Perl v5.14.1 built for i386-freebsd-thread-multi-64int
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Validation: is defined whether the variable?
by Perlbotics (Archbishop) on Aug 07, 2011 at 10:30 UTC | |
by breeze (Initiate) on Aug 07, 2011 at 10:55 UTC | |
| |
Re: Validation: is defined whether the variable?
by GrandFather (Saint) on Aug 07, 2011 at 12:12 UTC | |
by Anonymous Monk on Aug 07, 2011 at 12:24 UTC | |
Re: Validation: is defined whether the variable?
by Anonymous Monk on Aug 07, 2011 at 10:31 UTC |
Back to
Seekers of Perl Wisdom