I don't understand ... Why you are restricting this behavior to my...?
Every non-initialized variable is not defined.
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
UPDATE:
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.¹
1) anything else?
... of course boolean context including the defined operator won't throw a warning.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|