Writing a persistent perl script

前端 未结 4 457
無奈伤痛
無奈伤痛 2020-12-09 23:59

I am trying to write a persistent/cached script. The code would look something like this:

...
Memoize(\'process_fille\');
print process_file($ARGV[0]);
...
s         


        
4条回答
  •  眼角桃花
    2020-12-10 00:06

    If %my_hash in your example have moderate size in its final initialized state, you can simply use one of serialization modules like Storable, JSON::XS or Data::Dumper to keep your data in pre-assembled form between runs. Generate a new file when it is absent and just reload ready content from there when it is present.

    Also, you've mentioned that you would call this script in loops. A good strategy would be to not call script right away inside the loop, but build a queue of arguments instead and then pass all of them to script after the loop in single execution. Script would set up its environment and then loop over arguments doing its easy work without need to redo setup steps for each of them.

提交回复
热议问题