They are not exactly equivalent, in that the latter will read into $_, destroying any previous content. You would need to prepend the "local $_;" mantra to make them indistinguishable from calling code's point of view (though their precise behavior will still differ of course).
Anyway, on your question, I seem to recall word being that my-variables used directly in the loop construct (ie while(my $var) and for my $var) are scoped into the loop's block's context, but allocated in the surrounding block's frame. In conjunction with them apparently not being deallocated at the loop's end but rather at the surrounding block's end in older 5.5.x versions of Perl, that would explain why your code "leaks".
-
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.
|