Another way is to take advantage of pop's default behaviour of acting on @_ by calling an anonymous subroutine on the fly.
johngg@shiraz:~/perl/Monks$ perl -Mstrict -Mwarnings -E ' say sub { pop }->( 1, 3, 5, 7, 9 );' 9
I hope this is of interest.
Update: Note that shift can work the same way and that both by default operate on @ARGV in the main program.
johngg@shiraz:~/perl/Monks$ perl -Mstrict -Mwarnings -E ' say sub { shift }->( 1, 3, 5, 7, 9 );' 1 johngg@shiraz:~/perl/Monks$ perl -Mstrict -Mwarnings -E 'say pop' a b +c c johngg@shiraz:~/perl/Monks$ perl -Mstrict -Mwarnings -E 'say shift' a +b c a
Cheers,
JohnGG
In reply to Re: passing an array without a name to pop()
by johngg
in thread passing an array without a name to pop()
by TieUpYourCamel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |