That's know forever. Changing @_ elements directly is destructive. shift @_ creates a copy. With methods destroying $self (i.e. $_[0]) is of course evil.
Yes, I’m sure no one is really surprised at this. Everyone knows that the invocant is passed as the first argument of course, and almost everyone knows that elements in @_ are aliased. But on the caller end, syntactically, the invocant doesn’t look like an argument, so I had just never thought about this ramification of how Perl works. Once it occurred to me, I wasn’t even certain it would work this way, although I would have been surprised if it didn’t; so I tested it, and sure enough, it did what I expected.
People coming from other languages may be astonished at this, though.
That's know forever. Changing @_ elements directly is destructive. shift @_ creates a copy. With methods destroying $self (i.e. $_[0]) is of course evil.
Yes, I’m sure no one is really surprised at this. Everyone knows that the invocant is passed as the first argument of course, and almost everyone knows that elements in @_ are aliased. But on the caller end, syntactically, the invocant doesn’t look like an argument, so I had just never thought about this ramification of how Perl works. Once it occurred to me, I wasn’t even certain it would work this way, although I would have been surprised if it didn’t; so I tested it, and sure enough, it did what I expected.
People coming from other languages may be astonished at this, though.