Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Using Shift with Parameters in a subroutine

by Marshall (Canon)
on Oct 21, 2014 at 20:42 UTC ( [id://1104605]=note: print w/replies, xml ) Need Help??


in reply to Using Shift with Parameters in a subroutine

It appears to me that you are only passing 2 refs to the sub.
sub foo{ my ($query_ref, $session_ref) = @_; }
These refs should be references to hash tables.

In general, passing 10 parameters to a sub is not a good idea. Better is reference to a hash.

Replies are listed 'Best First'.
Re^2: Using Shift with Parameters in a subroutine
by capstan (Novice) on Oct 23, 2014 at 16:34 UTC
    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)
      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
Re^2: Using Shift with Parameters in a subroutine
by perlron (Pilgrim) on Oct 22, 2014 at 08:27 UTC
    ok. ill improvise then. thanks. the 10 parameters was purely hypothetical , as a programming possibility. thats all.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-19 07:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found