in reply to Why won't a hash in a hash work as a hash reference to create an object?

sub new { my ($account) = @_;

That's the problem. The first argument that new gets is the name of the class. So instead write

sub new { my ($class, $account) = @_; return bless $accounts{$account}, $class; }

Replies are listed 'Best First'.
Re^2: Why won't a hash in a hash work as a hash reference to create an object?
by Lady_Aleena (Priest) on Apr 07, 2012 at 21:22 UTC

    Thank you moritz. Quick question, what is the value of $class supposed to be?

    Have a cookie and a very nice day!
    Lady Aleena

      It's the name of the class. If you call new as a method:

      my $obj = Class->new;

      ... then it'll be the invocant.

      (Don't not call new as a method. You set yourself up for all kinds of mess that way.)


      Improve your skills with Modern Perl: the free book.