On May 31, 7:18 pm, [EMAIL PROTECTED] (Jonathan Lang) wrote:
> > 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.

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.

> >     $usr||= "test";
> >     $pwd ||= "test123";
>
> ...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




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to