Writing a persistent perl script

前端 未结 4 479
無奈伤痛
無奈伤痛 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-09 23:59

    You can't get the script to keep state. As soon as the process exists any information not written to disk is gone.

    There are a few ways you can accomplish this though:

    • Write a daemon which listens on a network or unix socket. The daemon can populate my_hash and answer questions sent from a very simple my_script.pl. It'd only have to open a connection to the daemon, send the question and return an answer.

    • Create an efficient look-up file format. If you need the information often it'll probably stay in the VFS cache anyway.

    • Set up a shared memory region. The first time your scripts starts you save the information there, then re-use it later. That might be tricky from a Perl script though.

提交回复
热议问题