develooper Front page | perl.perl5.porters | Postings from June 2013

[perl #7505] x operator not copying elements in 'for' list?

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
June 16, 2013 00:48
Subject:
[perl #7505] x operator not copying elements in 'for' list?
Message ID:
rt-3.6.HEAD-25680-1371343715-188.7505-15-0@perl.org
On Thu Aug 09 06:58:20 2001, mjd@plover.com wrote:
> 
> -----------------------------------------------------------------
> [Please enter your report here]
> 
> 
> 
>         $x = 'abcd';
> 
>         for (($x =~ /./g) x 2) {
>           print chop;
>         }
> 
> This prints "abcd".  I expected it to print "abcdabcd".  Apparently,
> when I chop the first item in the list, it also chops the fifth item.
> I was not expecting this aliasing to occur, if it is indeed occurring.

Considering that the repetition operator has worked this way for years now:

    sub {
        print \$_[0], "\n";
        print \$_[1], "\n"; # same address
    }->(($x) x 2)
    __END__
    SCALAR(0x7fc02982ef50)
    SCALAR(0x7fc02982ef50)

I think we should consider this not-a-bug.  Some code could be relying
on it.

(I know this ticket is marked resolved, but it is not fixed, and we
still have a to-do test for it.)

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: resolved
https://rt.perl.org:443/rt3/Ticket/Display.html?id=7505

Thread Previous | 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