Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Re: Pass local array by reference?

by hmerrill (Friar)
on Jan 21, 2003 at 21:02 UTC ( [id://228847]=note: print w/replies, xml ) Need Help??


in reply to Re: Pass local array by reference?
in thread Pass local array by reference?

I prefer to call a "receiving" variable what it really is, so in subroutine BAR, I would do this:
sub BAR { my $arrayref = shift; #This will receive the array *reference* from + FOO ### Then, I can refer to specific elements of the ### array using the arrayref: my $first_element = $arrayref->[0]; ### or by turning the arrayref back into an array: my @bar_array = @{$arrayref}; my $1st_element = $bar_array[0]; #code here }
Remember, FOO is passing an array *reference* to BAR, so BAR receives an array *reference* - just my preference for clarity to include "ref" in the name of the variable so it's easy to tell what the variable contains. HTH.

Log In?
Username:
Password:

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

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

    No recent polls found