in reply to Re: Perl Style: Is initializing variables considered taboo?
in thread Perl Style: Is initializing variables considered taboo?
Every non-initialized variable is not defined.
UPDATE:DB<1> print $a // "undef" undef DB<2> my $a;print $a // "undef" undef DB<3> our $a;print $a // "undef" undef DB<4> $a=1;print $a // "undef" 1
And in most cases accessing an undefined variable will be caught under use warning;.
DB<1> print $a DB<2> use warnings; print $a Use of uninitialized value $a in print at (eval 6)[/usr/share/perl/5.1 +0/perl5db.pl:638] line 2. .. DB<3> use warnings; $a=undef;print $a Use of uninitialized value $a in print at (eval 9)[/usr/share/perl/5.1 +0/perl5db.pl:638] line 2. .. DB<4> print $a++ 0
Notable exceptions of this warnings are some altering operators like ".=" and "++" and auto-vivication in hashes and arrays.¹
Cheers Rolf
1) anything else?
... of course boolean context including the defined operator won't throw a warning.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Perl Style: Is initializing variables considered taboo?
by BrowserUk (Patriarch) on Aug 21, 2010 at 16:38 UTC | |
by LanX (Saint) on Aug 21, 2010 at 16:42 UTC | |
by BrowserUk (Patriarch) on Aug 21, 2010 at 17:08 UTC | |
by LanX (Saint) on Aug 21, 2010 at 17:16 UTC | |
by BrowserUk (Patriarch) on Aug 21, 2010 at 17:37 UTC | |
|