develooper Front page | perl.perl5.porters | Postings from September 2016

[perl #129208] map sometimes does and sometime does not copy vals

Thread Next
From:
Father Chrysostomos
Date:
September 6, 2016 05:12
Subject:
[perl #129208] map sometimes does and sometime does not copy vals
Message ID:
rt-4.0.24-7240-1473138736-805.129208-75-0@perl.org
# New Ticket Created by  Father Chrysostomos 
# Please include the string:  [perl #129208]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=129208 >


I would expect these two to be equivalent:

$ ./perl -Ilib -le '$x = 4; sub {\@_; for (map {$_[0]} 1) { $_=3 } }->($x); print $x'
4
$ ./perl -Ilib -le '$x = 4; sub {\@_; for (map {shift} 1) { $_=3 } }->($x); print $x'
3

This is with v5.25.4-89-g05bda26, but the behaviour is ancient.  I get the same results with 5.8.7.

Depending on internal flags, map may or may not copy the value returned from the block.

I believe it should always copy, but I wanted to check to make sure before making the change.

-- 

Father Chrysostomos


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About