I know that there is a statement about this in one of the perl docs, although I cannot find it now.
From perlsyn:
NOTE: The behaviour of a "my" statement modified with a statement mod
+ifier conditional or loop construct (e.g. "my $x if ...") is undefine
+d. The value of the "my" variable may be "undef", any previously ass
+igned value, or possibly anything else. Don't rely on it. Future ve
+rsions of perl might do something different from the version of perl
+you try it out on. Here be dragons.
So the following:
my $v2 = -2 if 0;
Will have undefined and probably unexp(?:exted|licible) behavior. Don't do it! Don't use a my assignment with a conditional!
Define your variable first, then set it using the conditional.
-
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.
|