J
Joseph Ellis
Hello all...I am fairly new to Perl and am hoping to glean some advice
from those of you who have been around the Perl block a few times.
I am currently writing a program that consists of a handful of
subroutines, with one subroutine calling another subroutine, etc, all
to generate a particular hash.
So far I'm giving most of my variables file scope, but I don't think
that's really the best thing to do, stylistically and otherwise.
Consider the following (syntax notwithstanding)...
my $l, $m, $n, $o, $p;
my %hash;
sub one {
use / modify all those global variables;
&two();
return %hash;
}
sub two {
use / modify a couple of the scalars and the hash;
&three();
}
sub three {
use / modify a couple of the other scalars and the hash
}
Would it be advisable / more efficient / more aesthetically pleasing /
just plain better to create lexical variables within each subroutine,
passing copies of them around as arguments, or is the above
pseudo-script fine the way it is?
What if there were 15 variables and 20 subroutines? Or 30 variables
and 5 subroutines?
I'm just curious as to which method is better (subjectively or
objectively).
Thanks.
Joseph
from those of you who have been around the Perl block a few times.
I am currently writing a program that consists of a handful of
subroutines, with one subroutine calling another subroutine, etc, all
to generate a particular hash.
So far I'm giving most of my variables file scope, but I don't think
that's really the best thing to do, stylistically and otherwise.
Consider the following (syntax notwithstanding)...
my $l, $m, $n, $o, $p;
my %hash;
sub one {
use / modify all those global variables;
&two();
return %hash;
}
sub two {
use / modify a couple of the scalars and the hash;
&three();
}
sub three {
use / modify a couple of the other scalars and the hash
}
Would it be advisable / more efficient / more aesthetically pleasing /
just plain better to create lexical variables within each subroutine,
passing copies of them around as arguments, or is the above
pseudo-script fine the way it is?
What if there were 15 variables and 20 subroutines? Or 30 variables
and 5 subroutines?
I'm just curious as to which method is better (subjectively or
objectively).
Thanks.
Joseph