Hello everybody, I am currently struggling about how are we supposed to implement persistent variables in perl.

Let me clarify myself;

I have a Module which handle the users data, it contain a memberlist variable which is initially undefined.

My goal is to populate the list variable only once by reading a file.

The flow should theoretically be as follow :

My current tests shows that the variable either get unloaded after being populated from inside the package, or it always read the file to fetch the variables.

How am I supposed to implement this? I thought the code within package was only run at compile time unless it was within a sub.

I would still consider myself as a beginner when it come to server-side/perl programming, so don't hesitate to point out any flaws that would occur from using this kind of flow in a real-world case.

On a side note, if you have open source code that you strongly recommend studying available anywhere, please let me know. I used to read a lots about YABB Forum code but the more I read about it, the more I realize that the code is not strong / very efficient.

Thanks

###################################

Update

After further testing with the singleton patterns (Thanks McA) and my previous implementation, I have realized that the problem does not really reside in the semantics but in the way the perl software works

After a script has been executed, all the packages are unloaded from memory. Is there any way of making sure a package remain alive?


In reply to Data Persistence by ShaZe

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.