>>>>> "SB" == Steve Bertrand <st...@ibctech.ca> writes:

  SB> I make these hashes available globally, initially as undef. I have a

there is no such thing as an undef hash. it is either empty or
not. undef is a single value and hashes are always in pairs. never do
undef %hash or even worse %hash = undef (the latter will trigger a
warning). one big reason to never undef a hash is that it leads to using
defined on hashes which is totally wrong. defined will be true if the
hash (even when empty) if it ever had any keys in it. 

  SB> reset() function that defines and populates the data types (all hashes)
  SB> to a default state with default values. This reset function is called
  SB> whenever a change is made to the data between tests.

the best way to handle this is to declare the hashes in a proper scope
(say a sub) and pass refs to them to the test code. then when you call
the sub you will always get clean hashes. same is true if you just pass
empty hash refs to the test code. global hashes (globals in general) are
bugs waiting to happen unless you are very careful.

  SB> Instead of copy/pasting each test for all of the known types, I'd
  SB> like to iterate through a list of known type names, and then map
  SB> the name of the type to the hash with the same name. I think what
  SB> I want is a symbolic ref, but I can't quite figure out how to map
  SB> the hash to the name.

you want a hash of hashes. never use symrefs if you don't have to. the
rule is symrefs are for munging the symbol table, not for general
purpose data structures. the symbol table is just a specialized hash
tree anyway so it offers NO advantages over a regular hash tree but it
allows for all sorts of nasty hard to find bugs.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to