in reply to shift doesn't DWIM

There are enough times when one just wants to get rid of the first element in an array, via:

shift @array;
It would be a nuisance to have to create a spitoon-like variable just to catch the shift'ed element (thereby preserving $_). And it would be easy to forget to do this, leading to many chomped butts.

the lowliest monk

Replies are listed 'Best First'.
Re^2: shift doesn't DWIM
by japhy (Canon) on Jul 12, 2005 at 12:27 UTC
    I agree entirely. From a Huffman-encoding viewpoint, I'd say doing shift @a to discard the first element of the array and doing $_ = shift @a to put that discarded element in $_ is a far better allocation of characters than () = shift @a for discarding and shift @a for storing in $_. Not to mention those empty LHS parens look odd to some folks.

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart

      Very nice reply! With a rationale like that prodding my brain maybe I won't fall into this particular hole that I've invented for myself again.


      Perl is Huffman encoded by design.
Re^2: shift doesn't DWIM
by Fletch (Bishop) on Jul 12, 2005 at 12:22 UTC

    Not to mention it's analogous to the behavior of shift in shell scripts which is often used in this way (just a bare shift to toss the value in $1 after retrieving it previously; especially in getopt-ish code).

    --
    We're looking for people in ATL