Post-increment does not yield a new lvalue, but it does have an lvalue, and does modify the variable. Update: I don't what I was thinking about there. Post-increment has an rvalue. (That's what happens when you try to post a message just before quitting time!) However, below is still semi-interesting. Consider:
print "$_ and $i\n" for ($i = 1, $i++, $i++);
__OUTPUT__
3 and 3
1 and 3
2 and 3
The $i is being modified, and the value before the post-increment is used in the list. Playing around, you could do something like:
print "$_ and $i\n" for (\($i = 1, $i++, $i++));
print \$i , "\n";
__OUTPUT__
SCALAR(0x8176c44) and 3
SCALAR(0x815dcc0) and 3
SCALAR(0x815dad4) and 3
SCALAR(0x8176c44)
This shows that the first element of the list is the
$i variable, and that perl generates two temporary scalars to hold the values of
$i prior to increment. Also, the entire list is evaluated before iteration.
Interesting stuff you found here!
-
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.