Dear Monks
I am trying to store and retrieve the values via storage object. My main program use 3 packages:
1. Storage
2. Source
3. Destination

Now within Source.pm, I like to store some data using an object($storage) of Storage class and would like to access the same object in Destination.pm to retrive the value.

I have multiple instances of Source and Destination object and Storage class stores historical values as well which Destination objects uses any time. Where do I declare the $storage object? I try to use 'our' That doesn't seem to present $storage in the other packages.
I am trying to achieve something like

use Storage; our $storage = new Storage(); use Source; use Destination; my $input = 'source.txt'; while (<IN>) { $source = new Source($_); $destination = new Destination(); $source->storeData(); $destination->useData(); }
The storeData and useData should have access to the single $storage object all the time. I would rather not pass data around via objects. As multiple classes can access the same data using the storage object as desire.

Thanks,
Seeking art of storage
Artist


In reply to Storage Object by artist

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.