in reply to Reference is experimental

shift should normally be given an array, like shift @tmp;, that removes (and returns) the first element from @tmp. When you say shift $tmp[0];, shift thinks you're trying to give it an array reference (the first element of the array), so it tries to dereference $tmp[0], which doesn't work because it's not a reference and that's why you get the "Not an ARRAY reference" error. That's a feature that was added in Perl 5.14, but was experimental, which is why you get the "shift on reference is experimental" warning, and the feature was removed again in Perl 5.24. It was replaced by the Postfix Dereference Syntax.

Replies are listed 'Best First'.
Re^2: Reference is experimental
by stevieb (Canon) on Oct 20, 2016 at 14:39 UTC

    I don't believe that postfix-deref was a replacement for shifting an aref... it's just a different way to dereference references.

    The problem here is that $tmp[0] is a scalar, and back in the days where shifting refs was experimental, it assumed that anything not an array should be a reference to one.

    As you've said, that experiment ended, and in 5.24.0+, we now get something a little different and descriptive (albeit still with an experimental warning):

    perl -wMstrict -E 'my @a=(1); shift $a[0]' Experimental shift on scalar is now forbidden at -e line 1, at EOF Execution of -e aborted due to compilation errors.

      The experimental feature was abandoned for the operators that work on both hashes and arrays (keys, values and each) because the design couldn't work properly for all array-like and hash-like things.

      The same problem didn't exist for the operators that work solely on arrays (push, pop, shift, unshift and splice(?)), but the feature was also abandoned for them to avoid a lack of symmetry with keys, values and each. However, it's worth noting that it was mentioned that newly-created postderef lessened the need for these.

        However, it's worth noting that it was mentioned that newly-created postderef lessened the need for these.

        It would be interesting to ask whether there was ever any real requirement for either?

        Or was this just a flight of fancy by some dev overeager to leave fingerprints on the codebase, approved on the basis of who was proposing it, rather than a proper technical assessment of the need for, utility of, and "fit" of the proposal.