For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > June 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"
Paul Lalli

2007-06-01, 6:59 pm

On May 31, 7:18 pm, datawea...@gmail.com (Jonathan Lang) wrote:
>
> 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.
>
>
>
> 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.


False. Prototypes are *always* ignored on method calls, and can be
ignored on any other subroutine call by providing the & before the
subroutine name. Therefore, there is no way of knowing from the above
what will be in $usr or $pwd.

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


You should *really* follow your own advice. While not preferred, a
single arg bless() is perfectly legitamite.
$ perldoc -f bless
bless REF,CLASSNAME
bless REF
This function tells the thingy referenced by REF
that it is now an object in the CLASSNAME package.
If CLASSNAME is omitted, the current package is
used.

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


No, they will be set to "test" and "test123", respectively, if and
only if they had a false value prior to this step. As discussed,
there is no way of knowing that from the above code.

Paul Lalli



Sponsored Links







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

Copyright 2008 codecomments.com