Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

by johngg (Canon)
on Dec 03, 2019 at 22:44 UTC ( #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
Node Status?
node history
Node Type: note [id://11109633]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2020-05-26 13:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (150 votes). Check out past polls.

    Notices?