in reply to Storable - File empties itself?

my $fsize = -s $storeFile; print "filesize: $fsize\n"; die if $fsize == 0;

the above will check on the filesize as the script is running from within the script.

Also store {}, $storeFile will create the file to store that empty hash(ref) but not with zero size. So if you see zero size perhaps it's coming because you are re-initialising your code and re-running the part the file is created? And/or, as hippo suggests, store may mess up if it's called at the same time on the same file from 2 different processes without file-locking. See Re: Preventing multiple instances (References on flock and running one copy of a script at a time) (random link I recall seeing lately) for file locking.

Replies are listed 'Best First'.
Re^2: Storable - File empties itself?
by feumw (Sexton) on Apr 13, 2023 at 11:54 UTC
    >> the above will check on the filesize as the script is running from within the script.
    Good idea.

    >> So if you see zero size perhaps it's coming because you are re-initialising your code and re-running the part the file is created?
    I haven't thought about this. Of course it's possible that multiple users working in the CMS might click at the same time. I'd assume that the Controller handles those but I can't make sure that there is only a single process using that file.

    I added your filesize/check as well as I added some "dies" and when I start my test-script in 2 different shells the second one immediately stops
    filesize: 9254 retrieve-error: at ../bin/store.pl line 19.
    I'll adjust out function a little and instead of die I might just let it Debug into an Logfile for now.