Though I was not able to compile the codesub 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}
In reply to Re^3: Using 'Shift' in subroutine argument
by shmem
in thread Using 'Shift' in subroutine argument
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |