in reply to shift in list context buggy?

To me it's perfectly clear why those two behave differently: shift() returns a scalar, splice() returns a list.

Putting a function that is "scalar context only" in a list context will give you a list with one element. No special magic to (surprisingly) return an empty list here.

Many builtins have list context semantics, but for shift() I'd have no idea what would make sense. Although a "shift ARRAY, COUNT" semantics might be handy sometimes. But even then I'd expect shift to always return exactly COUNT elements, even if ARRAY was empty.


Search, Ask, Know

Replies are listed 'Best First'.
Re^2: shift in list context buggy?
by LanX (Saint) on Nov 12, 2013 at 14:14 UTC
    > To me it's perfectly clear why those two behave differently: shift() returns a scalar, splice() returns a list.

    They are documented to be equal...

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      They are documented to be equal...

      ... when used in a void context!


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      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.
        > ... when used in a void context!

        And where is this supposed to be documented?

        splice doesn't even mention "void".

        Cheers Rolf

        ( addicted to the Perl Programming Language)