Beefy Boxes and Bandwidth Generously Provided by pair Networks Russ
Keep It Simple, Stupid
 
PerlMonks  

Re: Parameters, subs and the shift function

by edan (Curate)
on Aug 19, 2003 at 07:15 UTC ( [id://284853]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Parameters, subs and the shift function

You went to the trouble of writing some nice test code, but did you run it? It might help answer some of your questions...

First, shift only takes one element off the parameter list, so your test sub will give you:

$number = 3; @array1 = ("mary"); @array2 = ("had");

As for how the arguments are passed to the function, perl flattens out the argument list, so it will arrive as one big list (@_ to be exact), and you won't be able to tell where one list end and another begins. If you need to do this, you'll have to pass references, like so:

sub test { my $number = shift; my $arrayref1 = shift; my $arrayref2 = shift; # remember to dereference: @$arrayref1 etc. } # ......... my @a = ("mary","had","a","little","lamb","!"); my @b = ("London","Bridge","is"); # call sub test(3,\@a,\@b);

HTH

--
3dan

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://284853]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.