Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: passing an array without a name to pop()

by johngg (Canon)
on Dec 03, 2019 at 22:44 UTC ( [id://11109633]=note: print w/replies, xml ) Need Help??


in reply to passing an array without a name to pop()

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11109633]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-03-28 22:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found