# New Ticket Created by  "Carl Mäsak" 
# Please include the string:  [perl #116731]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=116731 >


<uvtc> r: my @a = <foo bar baz>; map( { s/a/A/ }, @a ); say @a;
<p6eval> rakudo a3869a: OUTPUT«foo bar baz␤»
<uvtc> Hm. Was expecting foo bAr bAz there.
<uvtc> In Perl 5, if I put an s/// inside a `map`, it modifies the
items in the array. Does Perl 6 behave the same way?
<moritz> n: my @a = <foo bar baz>; map( { s/a/A/ }, @a ); say @a;
<p6eval> niecza v24-23-g0520c7c: OUTPUT«foo bAr bAz␤»
<moritz> uvtc: I think it's a bug in rakudo
* masak submits rakudobug
<moritz> somwhere the rw-ness of $_ gets lost
<uvtc> Thanks!
<colomon> huh, I would have thought that was a nieczabug
<uvtc> Why does s/// inside the `map` change the original array? Is it
because that's what most commonly wanted in that situation?
<masak> it's because $_ is bound rw.
<masak> as in <-> $_ { ... }
<uvtc> It would seem to me that if I want to change the array, I'd use
a `for` loop. Whereas, `map` would be used exclusively for creating
new arrays.
<moritz> uvtc: map and for loops are really the same in Perl 6
<uvtc> Ah. Ok. Thanks.

Reply via email to