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

Re: Passing references to a sub.

by the_slycer (Chaplain)
on Apr 01, 2002 at 16:42 UTC ( [id://155866]=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 Passing references to a sub.

The other use of references is when you need to pass two arrays (or a hash and an array) into a sub.
Consider:
my @array1 = ("foo", "foo1", "foo2"); my @array2 = ("bar", "bar1", "bar2"); print_data(@array1, @array2); sub print_data { @array1 = @_; #array1 gets all of @_ @array2 = @_; #array2 also gets all of @_ }
vs
print_data(\@array1, \@array2); sub print_data { my @data1 = @{$_[0]}; #dereferences first array into @data1 my @data2 = @{$_[1]}; #dereferences second array into @data2 }
The second version is more often than not what you actually want.

Log In?
Username:
Password:

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