For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > May 2007 > Re: Error:Can't locate object method "prepare" via package "abc"









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Error:Can't locate object method "prepare" via package "abc"
Jonathan Lang

2007-05-31, 6:59 pm

Alma wrote:
> Hi ,
>
> Urgent help.
>
> I have written 2 modules one abc.pm & xyz.pm (admin modules).
>
> abc.pm
> --------------------------------------
> my $databasehandle;


Note that this establishes a single $databasehandle for every object
of type 'abc' that you create; it does not create a separate one for
each object.

> sub new($){
>
> my ($self,$usr,$pwd) = @_;


Again, you have a signature problem. 'sub new($)' says that 'new'
will take a single scalar as a parameter; as such, @_ will only ever
have one value in it: $usr and $pwd will always be set to null.

Also, read up on the syntax of 'bless' a bit more. IIRC, saying
'bless $self;' is not enough.

> $usr||= "test";
> $pwd ||= "test123";


....and thus $usr and $pwd will always equal "test" and "test123",
respectively.



> sub DESTROY(){
> my $self;
> $self->disconnect();
> }


You never set $self to anything. Change the '()' in 'sub DESTROY()'
to '($)', or remove them altogether; then change 'my $self;' to 'my
$self = shift;' or 'my ($self) = @_;'

--
Jonathan "Dataweaver" Lang
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com