B
Bob
I'm updating a fairly old Perl script. Before I change what seems to
be a strange practice, I want to be sure the original author wasn't
exploiting some efficiency trick.
The hash %foo is used only within a subroutine, but rather than declare
it in the subroutine, he declares it in the global context and passes a
reference to it into the subroutine:
#!/youwouldnotbelievethispath/perl
#GLOBALS
my %foo;
#SUBROUTINES
sub processData {
my $fooRef=@_[0]; # he doesn't like "shift".
// do stuff with $$fooRef{}
}
#MAIN
processData(\%foo);
Again, the hash is not used outside of the subroutine, and there's no
reason to believe that it ever would have been. He actually does
this with several different hashes.
The reason I'd like to do away with it is that within the subroutine,
each time he reads a new line of data from a file, he loops through
(keys %{$fooRef}) deleting each one. There are quite a few, so I'd
rather just undef the hash and build it again.
Thanks
--
be a strange practice, I want to be sure the original author wasn't
exploiting some efficiency trick.
The hash %foo is used only within a subroutine, but rather than declare
it in the subroutine, he declares it in the global context and passes a
reference to it into the subroutine:
#!/youwouldnotbelievethispath/perl
#GLOBALS
my %foo;
#SUBROUTINES
sub processData {
my $fooRef=@_[0]; # he doesn't like "shift".
// do stuff with $$fooRef{}
}
#MAIN
processData(\%foo);
Again, the hash is not used outside of the subroutine, and there's no
reason to believe that it ever would have been. He actually does
this with several different hashes.
The reason I'd like to do away with it is that within the subroutine,
each time he reads a new line of data from a file, he loops through
(keys %{$fooRef}) deleting each one. There are quite a few, so I'd
rather just undef the hash and build it again.
Thanks
--