Go Back   Velocity Reviews > Newsgroups > PERL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

PERL - Is this an efficiency hack of some sort?

 
Thread Tools Search this Thread
Old 02-22-2007, 08:22 PM   #1
Default Is this an efficiency hack of some sort?



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


--



Bob
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump