Is this an efficiency hack of some sort?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob

    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:

    #!/youwouldnotbeli evethispath/perl

    #GLOBALS
    my %foo;


    #SUBROUTINES
    sub processData {
    my $fooRef=@_[0]; # he doesn't like "shift".
    // do stuff with $$fooRef{}
    }

    #MAIN
    processData(\%f oo);


    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


    --

Working...