in reply to Re: Using 'Shift' in subroutine argument
in thread Using 'Shift' in subroutine argument

If you execute this
use strict; use warnings; one(1,2,3,4); sub one{ &two (shift, shift); } sub two { print "Elements : \n @_ \n"; }
you would get
Elements : 1 2
Which means that it's same as passing the first two elements of the list the sub-routine one has received.Though I was not able to compile the code
sub one{ &two shift, shift; }
which is your case.Provide the some context of your snippet that would help everyone to learn.

The world is so big for any individual to conquer

Replies are listed 'Best First'.
Re^3: Using 'Shift' in subroutine argument
by shmem (Chancellor) on Nov 02, 2007 at 13:20 UTC
    Though I was not able to compile the code
    sub one{ &two shift, shift; }

    That's a syntax error. Subroutine invocations with & require parens.

    Drop the ampersand and move the sub two definition up:

    use strict; use warnings; one(1,2,3,4); sub two { print "Elements : \n @_ \n"; } sub one { two shift, shift; }

    To resolve the bareword two as a subroutine call (in two shift, shift), the compiler needs to have seen the sub declaration already. Alternative:

    use strict; use warnings; sub two; # forward declaration one(1,2,3,4); sub one { two shift, shift; } sub two { print "Elements : \n @_ \n"; }

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}