Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re: Use a Serialized Hash... When It Might Not Exist?by kcott (Archbishop) |
on Nov 12, 2022 at 02:33 UTC ( [id://11148154]=note: print w/replies, xml ) | Need Help?? |
G'day redapplesonly, "I am working on a Perl (v5.30.0) script that needs to use stateful information from the previous run of the script." All of your steps, and other design notes, seem spot-on to me. :-) "But here's the problem: What about the first time the script runs?" That's a very valid point. I don't use Storable very often, but when I do I encounter the same issue. I usually handle this by dealing with it before runtime execution starts in an INIT block. Here's a rough example of how I might have written your code (pm_11148149_storable_first_run_0.pl):
I added some extra statements for reporting/demo purposes (pm_11148149_storable_first_run_1.pl):
Here's some equivalent output to your sample run:
Notes:
— Ken
In Section
Seekers of Perl Wisdom
|
|