in reply to Re^8: Does @{ } copy arrays?
in thread Does @{ } copy arrays?

And yes of course I consider my example to pass $#a as an argument an extremely common case.

The validity of your example as a counter-argument relies not just upon passing $#a as an argument to a sub, but also on:

  1. Not assigning the arguments to named lexicals within the sub as is normal:
    sub ...{ my( ..., ... ) = @_; }
  2. And then, using the $_[...] alias as an lvalue.

I bet you cannot find a single example of anyone doing this on cpan; or in any publically available piece of real code.

Ergo, not a common case.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP PCW It is as I've been saying!(Audio until 20090817)

Replies are listed 'Best First'.
Re^10: Does @{ } copy arrays?
by LanX (Saint) on Oct 23, 2009 at 19:43 UTC
    sigh...

    Look a compiler must cover _all_ cases not only what you consider "common"...

    Cheers Rolf

      Sigh...

      And well you might. You're obviously finding this quite hard. Read back. No one suggested that the compiler should suddenly stop catering for all cases did they!

      Prior to this recent change, both lvalue and rvalue uses--and yes, even your obscured, aliased lvalue assignment--worked just fine. And they didn't double or treble the size of small anonymous arrays in the process. But subsequent to this change, any reference to $#--lvalue or rvalue--has the immediate affect of adding magic to the array, regardless whether it is actually used!

      My suggestion was that the application of magic be deferred until it is actually required--when it is used as an lvalue--rather than when it is first referenced. As ikegami has demonstrated, that is perfectly feasible to do.

      The whole point about knowing which are the common cases, and which are the obscure--may only happen in golf and pointless demonstrations--cases, is that you optimise for the former, not the latter.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.