On Dec 10, 2007 3:53 AM, shmem <[EMAIL PROTECTED]> wrote:
> Well, if we were to return an array reference instead of a hash ref,
>
> sub [EMAIL PROTECTED],shift}
>
> works. Why does the shift get executed before an array reference is
> constructed - but not if a hashref is constructed - from an array?

No it doesn't. It breaks in various and subtle ways, at least on a
couple versions of Perl that I used.

I actually did this once. (The class was representing vectors to
overload various operators, so it made sense to use a blessed array
ref.) The problem is that perl doesn't really refcount @_, so [EMAIL PROTECTED]
gives you a very unstable object whose contents are apt to change
underneath you for no apparent reason. I think you're probably fine as
long as you're within the call that the @_ belongs to, but if you ever
return it, weird stuff happens.

I can't come up with a simple test case for it. But it seems
reasonable that "fixing" the problem would slow everything down, and
in this case I'd rather have the speed. I'm not convinced that it's
really a bug anyway, as long as it doesn't crash. Making a copy is
what I really intended with that code; I didn't *want* a reference to
an argument list. I'm not even sure what that would mean.

Reply via email to