Is this an efficiency hack of some sort?

Discussion in 'Perl' started by Bob, Feb 22, 2007.

  1. Bob

    Bob Guest

    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, Feb 22, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nobody
    Replies:
    0
    Views:
    565
    nobody
    Jun 1, 2004
  2. JerryJ
    Replies:
    11
    Views:
    1,428
    Dave Moore
    Apr 28, 2004
  3. Is this some kind of hack

    , Dec 3, 2008, in forum: C Programming
    Replies:
    4
    Views:
    380
    Keith Thompson
    Dec 3, 2008
  4. Stephen Horne
    Replies:
    3
    Views:
    638
    Stephen Horne
    Aug 5, 2009
  5. Navin
    Replies:
    1
    Views:
    761
    Ken Schaefer
    Sep 9, 2003
Loading...

Share This Page