in reply to Re: ttchop()/tt and list assignments
in thread chop() and list assignments

I should have been more specific about how we arrived at the problem. I wanted the function to work if it was passed a literal (remember that the elements of @_ are aliases, and that an assignment to @_ "de-aliases" @_'s elements). sub foo {chop @_}; would trip a Modification of a read-only value attempted error if passed 'string' or 10 + 100.

At any rate, this was just in fun, and I noticed this "problem" and wanted to find out why Perl was behaving this way.

Replies are listed 'Best First'.
Re: Re: Re: chop() and list assignments
by japhy (Canon) on Mar 06, 2001 at 08:49 UTC
    No one has addressed the problem. Here is debugger code:
    DB<8> x chop(@a = ('abc','def','ghi')) 0 'c' DB<9> @a = qw( abc def ghi ) DB<10> x chop(@a) 0 'i'
    This feels so very wrong. What is that list assignment doing to chop()? Is it, for some reason, returning the last element assigned? All of the elements in the array are modified. Yet there are different return values. This is ungood.

    This occurs in 5.6.0. And it happens in bleadperl. This is a bug. It feels so bad.

    japhy -- Perl and Regex Hacker

      This same behavior exists in 5.004. Notice a similar "problem" with chop( @a[0..2] ).

      It certainly seems like a bug but, I have to say, I can't get too worked up about it as being a serious bug. But a bug report is in order.

              - tye (but my friends call me "Tye")