Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Using Shift with Parameters in a subroutine

by capstan (Novice)
on Oct 23, 2014 at 16:34 UTC ( [id://1104797]=note: print w/replies, xml ) Need Help??


in reply to Re: Using Shift with Parameters in a subroutine
in thread Using Shift with Parameters in a subroutine

Just to be thorough,

my ($one, $two) = _@;

works once, but ignores the side effect of shift (removing the arguments from the @_ array).

As Marshall says, using a reference to an array would be the best way to deal with a lot of parameters, but if you wanted to, say, process two at a time, you could do

while (my ($one,$two) = splice @_, 0, 2) { #do something }
(you'll get an uninitialized value warning if you supply an odd number of parameters)

Replies are listed 'Best First'.
Re^3: Using Shift with Parameters in a subroutine
by perlron (Pilgrim) on Oct 25, 2014 at 17:59 UTC
    thanks. i didnt realise this earlier, about the impact on @_ .
    Do not wait to strike when the iron is hot! Make it hot by striking - WB Yeats

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-03-29 02:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found