At 7:24 PM -0700 11/2/10, Sri wrote:
Hi
I am trying to call an array defined in function1 in other function2,
function3 etc. How can I implement it. Plz help me.
function1 {
@months = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/;
}
function 2 {
}
function 3 {
}
Edit/Delete Message
Declare the array outside of the two functions:
my @months;
function1 {
@months = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/;
}
function 2 {
# use @months here
}
Of course, now you have a global array. It is usually better not to
reference global arrays inside a function, so pass the array as an
argument:
my @months;
function1(\...@months);
function2(\...@months);
function1 {
@{$_[0]) = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/;
}
function 2 {
# use @{$_[0]} here
}
That said, i use global arrays all the time. They are easier. :)
See 'perldoc perlsub' for details.
--
Jim Gibson
[email protected]
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/