J
jl_post
Hi,
Recently I was reviewing someone's Perl code and I saw that his
code used a few global variables that were set and accessed by several
functions. Since I am not a fan of global variables, I edited the
code to get rid of all but one of them.
(For the record, his code used "strict" and "warnings".)
The remaining global variable was a hash. I proceded to edit the
code so that the functions took a hash reference as an input
argument. So previously, the code looked something like:
my %hash;
{
f1();
f2();
f3();
f4();
}
sub f1 { ... }
sub f2 { ... }
sub f3 { ... }
sub f4 { ... }
(This is a simplification.)
I changed those lines to something like:
sub f1 { ... }
sub f2 { ... }
sub f3 { ... }
sub f4 { ... }
{
my %hash;
f1(\%hash);
f2(\%hash);
f3(\%hash);
f4(\%hash);
}
In the function definitions themselves, I added code to read in the
input arguments, like this:
sub f
{
my ($hashRef) = @_;
Recently I was reviewing someone's Perl code and I saw that his
code used a few global variables that were set and accessed by several
functions. Since I am not a fan of global variables, I edited the
code to get rid of all but one of them.
(For the record, his code used "strict" and "warnings".)
The remaining global variable was a hash. I proceded to edit the
code so that the functions took a hash reference as an input
argument. So previously, the code looked something like:
my %hash;
{
f1();
f2();
f3();
f4();
}
sub f1 { ... }
sub f2 { ... }
sub f3 { ... }
sub f4 { ... }
(This is a simplification.)
I changed those lines to something like:
sub f1 { ... }
sub f2 { ... }
sub f3 { ... }
sub f4 { ... }
{
my %hash;
f1(\%hash);
f2(\%hash);
f3(\%hash);
f4(\%hash);
}
In the function definitions themselves, I added code to read in the
input arguments, like this:
sub f
{
my ($hashRef) = @_;