A coworker and I are looking at an inheritance problem here at work. We have a particular class used for settings. For our parent class, we have several package variables that correspond to global settings. Children modules would then add specific settings for their instances.

The problem comes into play when we want to access the global or common settings. The functionality we would like is that of C++ static variables where any class can change the variable and it is visible to all.

Is there some way to mimic this functionality in perl?

To be specific, suppose we have a parent class A with setting "knob1". We would access this normally with:

$A::knob1

If we have a module B that inherits from A, we would like to be able to change knob1 in the following way:

$B::knob1 = 0;

And have $A::knob1 be automatically updated.

Then we get even more complex with another child of A, say, module C. Module B and Module C are at the same level and share module A as an ancestor. But a change in module C to a globally (inherited) setting should be visible in module B.

Any ideas?


In reply to Static Variables in Perl by RollyGuy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.