Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Parameters, subs and the shift function

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


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
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-23 11:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found