ShaZe has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Data Persistence
by McA (Priest) on Nov 20, 2014 at 14:21 UTC | |
by ShaZe (Novice) on Nov 20, 2014 at 14:40 UTC | |
by McA (Priest) on Nov 20, 2014 at 14:57 UTC | |
by ShaZe (Novice) on Nov 20, 2014 at 15:47 UTC | |
by Laurent_R (Canon) on Nov 20, 2014 at 23:27 UTC | |
|
Re: Data Persistence
by CountZero (Bishop) on Nov 21, 2014 at 07:16 UTC | |
by choroba (Cardinal) on Nov 21, 2014 at 09:52 UTC | |
by CountZero (Bishop) on Nov 21, 2014 at 16:27 UTC |