Re: To Reference or not to reference



On 3/29/07, Dukelow, Don <don.dukelow@xxxxxx> wrote:
I've written a Perl program that declares a hash at the top of the
program "%myHask;". It has worked great until now when one sub program
seams to be making its own copy of the hash. I can find no typo's or
anything but there my still be one there. My question is would it be
better to pass the global hash by reference to each sub program to cut
down on possible typo errors or just leave it global and fix the problem
I have?

Don Dukelow

I can say with near 100% certainty that passing a ref is better than
using a global. Also, if you are finding your self writing code that
is focused around a hash that you are calling a number of functions on
then what you are really doing is writing OO code in a non-OO fashion.
Consider refactoring the code as object based instead of hash based.
.



Relevant Pages

  • Re: To Reference or not to reference
    ... If your basic data structure is a hash, ... sugar surrounding some simple data constructs? ... It has worked great until now when one sub program ... if you are finding your self writing code that ...
    (perl.beginners)
  • To Reference or not to reference
    ... I've written a Perl program that declares a hash at the top of the ... It has worked great until now when one sub program ... seams to be making its own copy of the hash. ... better to pass the global hash by reference to each sub program to cut ...
    (perl.beginners)