Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

(jeffa) 3Re: scoping large arrays - newbie Q

by jeffa (Bishop)
on Jun 18, 2002 at 05:39 UTC ( [id://175285]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: scoping large arrays - newbie Q
in thread scoping large arrays - newbie Q

With the example you have given, i say point A, because if you declare your array at point B, you will re-declare it as many times as you call mySub(). Also, consider passing @bigarray to mySub() as a reference. Just be sure to declare mySub() before @bigarray, otherwise @bigarray is accessible by mySub():
use strict; sub mySub { my $ref = shift; for (@$ref) { #do stuff with array } } my @bigarray = ("insert", "a very", "long list here"); my $thing1 = mySub(\@bigarray); my $thing2 = mySub(\@bigarray);
If the array in question is only pertinent to the subroutine, and either that sub will only be called once or the array will change with each sub call, then declare the array inside the subroutine.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-04-24 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found