The literal reference is just a value which in your map just happens to be contained in $_. When you reassign 1 to it, it's not changing the reference in any way, you're just putting something else in $_ (although this is where I'm getting fuzzy and agree it's somewhat weird); it's just that $_ just happens to be aliased to some temporary SV* / SVrv that the map is using as its argument list. The assignment isn't changing the referenced value, it's just sticking the new SViv 1 into that SV*.
DB<1> $a = $b = [qw/a b c/]
DB<2> x map { $_ = 1 } $a
0 1
DB<3> x $a
0 1
DB<4> x $b
0 ARRAY(0x7fa8144335b0)
0 'a'
1 'b'
2 'c'
Hopefully someone more conversant in perlguts than I might can explain it better.
The cake is a lie.
The cake is a lie.
The cake is a lie.
-
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.
|