in reply to Re^2: how to code a class and use it with hash of hash as data member?
in thread how to code a class and use it with hash of hash as data member?

i guess I am hugely confuse about when to use $self->...
in the first reply to my question, the code uses the
%serverMap directly in each of the methods.. i guess because i define it outside all methods, it is visible???...
but in yours, you use $self to access to it.
another question of mine: i se eyou make a new constructor (more compact one), but
don't quite get what it does? your decision for the change? my original verison has this package @ISA CLASS::Singleton...
to prevent users of this class to have more than 1 copy of serverMap
.. but from your comment in your psot, is that step necessary anymore? thanks
  • Comment on Re^3: how to code a class and use it with hash of hash as data member?

Replies are listed 'Best First'.
Re^4: how to code a class and use it with hash of hash as data member?
by chromatic (Archbishop) on Mar 17, 2006 at 19:50 UTC

    The purpose of using $self is so that you can have more than one object, each with its own member data. The original code allowed people to create multiple objects, but each accessed the same hash. I don't see any real reason to use objects in that case.

    My $self doesn't access %serverMap. Each object gets its own copy of that data.

    I changed my constructor to throw out unnecessary code and to allow inheritance by using the two-argument form of bless, which is almost always the right thing to do.

    My code doesn't create a singleton, but I wasn't sure if you needed that.

      hi i get an compile error in
      my %self = %{ $serverMap{ default } }, @_;
      error is "Useless use of variable in void context".
      I think it is complaining about @_? but not quite
      sure what it means .. i guess the code tried to set %self
      to default if people don't enter a hash of hash as part of new. should that be
      %{ $serverMap{ default } } || @_
      ?? thanks