in reply to Can't use string as a HASH ref while strict refs

I can see two problems. Change:
my $foo = MyModule::->new($dbh);
unless that's just a typo, into
my $foo = MyModule->new($dbh);
Also as was mentioned previously, you probably want to change your new function to start like:
sub new { my $class = shift; my $self = {}; # self is a hashref. bless $self, $class; .... }
because the very first thing your new function gets passed when you call it as MyModule->new(), is a scalar containing the string "MyModule". You can bless that scalar into any class you might like, but you can't magically make it turn into a hashref. Without reassigning it anyway.

Replies are listed 'Best First'.
Re: Re: Can't use string
by wlinx (Initiate) on Jan 09, 2002 at 11:22 UTC
    Sorry, I'm such a retard. Mistake copying a method to the constructor. Anyway, to address two things: sorry for the indentation-- i do indent! i was just lazy and typing in from memory. more importantly-- $obj = MyModule::->new; is perfectly valid, although ugly; (pg 316 of Camel has a great bit). Basically, it says that: $obj = MyModule->new; if fine most of the time, but could be confusing if MyModule is the same of a subroutine (unlikely, I know), which would parse as $obj = MyModule()->new();, where the extra :: is guarenteed to parse correctly.
      I stand corrected. Thanks.