Is this an efficiency hack of some sort?

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


--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top