I'm not sure exactly what you're looking for. "Inheritance" is a term specific to object oriented programming that describes one way to say "This thing acts like this other thing, perhaps with some small changes."
Inheritance may be one way to solve what you're doing here, but I don't think it is.
You have a couple of options for making one variable or object available across multiple modules:
- Make it a global and always access it via a namespace, with something like $DB::Package::dbh. This has the drawback that you can't control who reads from or writes to it. That can be hard to debug.
- Add it to the export list wherever you need it. This is still effectively a global variable, but it's a little less messy.
- Store all of the database-related stuff in an object or package of its own and don't let it leak out anywhere else. This is a good practice anyway because it's easier to find what you need to change and because with good encapsulation it's more difficult to change things elsewhere accidentally.
- Add an accessor to your database-related module from which to retrieve your database handle and only ever grab it via the accessor, perhaps my $dbh = DB::Package->fetch_dbh().
There are other options, but they're mostly variants of these strategies. I do suggest modularizing your code by behavior and duty, though. It has many other benefits.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.