in reply to Re:^2 $self->{foo} in sub new {}
in thread $self->{foo} in sub new {}

It is usually a good idea to use the $class = ref($class) || $class so a new object can be created from an existing object.
No. Quite the opposite, according to those who have looked at it in depth. See "Why ref($proto) should be avoided" and "ref($proto) - just say no!".

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

  • Comment on •Re: Re:^2 $self->{foo} in sub new {}

Replies are listed 'Best First'.
Re: ^4 $self->{foo} in sub new {}
by flounder99 (Friar) on Dec 22, 2003 at 15:23 UTC
    I stand corrected. I just had this hammered into my head from examples in the camel/panther/ram books (sorry I never bought the llama book, maybe I should have) and perltoot. I don't have the books in front of me so if one of these don't do it this way, my appologies. I'm just running on memory.

    --

    flounder

Re: •Re: Re:^2 $self->{foo} in sub new {}
by Taulmarill (Deacon) on Dec 22, 2003 at 15:46 UTC
    ok, you managed to confuse me.
    i read the nodes you posted but i dont think i understood them completely, so could you or someone else give me a pointer where i lern to code nice and clean perl objects?

      merlyn's perlboot is pretty good.

      Yes, I know tchrist suckered a lot of people into thinking ref($proto) || $proto is OK.

      ----
      I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
      -- Schemer

      : () { :|:& };:

      Note: All code is untested, unless otherwise stated