scott_apc has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Is there any way to use one command instead of doing the following: shift @dn; shift @dn; shift @dn; pop @dn; Regards, Scott

Replies are listed 'Best First'.
Re: Shift Question
by ikegami (Patriarch) on Feb 16, 2009 at 10:11 UTC

    Removing from the ends is most efficient:

    splice(@dn, 0, 3, ()); pop(@dn);

    But unless you have a huge array, you might want the more readable:

    @dn = @dn[3..$#dn-1];
      I know it's a sad idictment on the capabilities of some clients with which I've worked, but a large number of them would prefer the former since they wouldn't even have thought of the latter (including me;-) - but unlike them (who would consider it to be obfuscated &/or voodoo), I do understand (and yes, even prefer:-) it!!

      A user level that continues to overstate my experience :-))
        Thanks You!!!
Re: Shift Question
by Corion (Patriarch) on Feb 16, 2009 at 09:52 UTC

    Maybe you want splice? But it's hard to tell, as you don't tell us exactly what you want to achieve.

Re: Shift Question
by irah (Pilgrim) on Feb 16, 2009 at 09:54 UTC
    I feel it's possible by splice function. Please read about splice function from perldoc.