Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Just another Perl shrine
 
PerlMonks  

Re: Re: OOP Access of variables

by simeon2000 (Monk)
on Mar 08, 2001 at 16:35 UTC ( [id://63023]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re: OOP Access of variables
in thread OOP Access of variables

Theo: Thanks, that's a good idea. I just have another question:

If I also have a TArt::Article package data object, and I call the script like this:

package main; use TArt::Editor; use TArt::Article; my $ed = new TArt::Editor; my $art = new TArt::Article;
If both of these packages (TArt::Editor, TArt::Article) use TArtLib, would they both get the same $dbh object when calling TArtLib->dbh, or would it be two separate TArtLib packages (and thus, two database handle objects)?

Replies are listed 'Best First'.
Re: Re: Re: OOP Access of variables
by TheoPetersen (Priest) on Mar 08, 2001 at 16:38 UTC
    Assuming the code I gave you, there would be only one $dbh. (Hey, that's a catchy phrase ... :)

    When learning Perl objects (or Perl anything else), follow your hunches and try them out. You'll develop both knowledge and intuition quickly. That's the nice thing about Perl's learning curve, you can almost always do useful work along the way.

      Theo: You were right! I forgot that Packages and the object they create are separate. I figured for each Article or Editor I created, there'd be a new $dbh handle, but since it's global in TArtLib, the ref on the $dbh returned the same memory address for both packages' copy of $TArtLib::dbh :) Thanks so much to everyone for help. I learned a lot more about packages and objects today :)
      I'd just add in here for clarification of the SoPW poster that $dbh is a reference to your database object (the arrow operator for the DBI functions should be a big tip-off :D); using the "my $dbh = TArtLib->dbh();" anywhere else gains you a local copy fo the reference, but the reference still points to the single copy of the object that holds the DB connection.


      Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://63023]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.