Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Parameters, subs and the shift function

by CombatSquirrel (Hermit)
on Aug 19, 2003 at 08:16 UTC ( [id://284866]=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

Just one thing to add to what the others said: Although discouraged by some, I personally fancy prototypes. In the following example prototyping the function makes it seem (this "seem" is important) as if you just needed arrays and not references to arrays; the references are automatically generated by Perl.
#!perl use strict; use warnings; sub test ($\@\@) { my $number = shift; my @array1 = @{+shift}; # Shift off the reference, and dereference + it my @array2 = @{+shift}; # Print the variable contents print $number . $/ . join(' - ', @array1) . $/ . join(' - ', @array +2) . $/; } my @a = qw(mary had a little lamb !); my @b = qw(London Bridge is); test (2, @a, @b); __END__ OUTPUT: 2 mary - had - a - little - lamb - ! London - Bridge - is
Have a look at perlsub for an explanation of prototypes. Please note that the above only works for arrays and not for lists.
Hope this helped.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://284866]
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.