[Chicago-talk] Using Storable to exchange data between 2 processes

Don Drake don at drakeconsult.com
Fri Jan 23 14:06:58 CST 2004


I would modify the child to write to a temp file, then rename it to the real
file.  The 'mv' command in Unix is an atomic call, so you'll never have a
file in an inconsistent state (partially written).  The rename function is
portable, but has known issues when renaming across file systems, etc. on
certain platforms.

-Don



 sub child {

         foreach (0..60) {
                 sleep 1;
                 $data{IBM}{last} = $_;
                 store(\%data,'/tmp/jstrauss.tmp');
		     rename ('/tmp/jstrauss.tmp','tmp/jstrauss');
		     # or if you're running unix:
		     # system("/bin/mv -f /tmp/jstrauss.tmp /tmp/jstrauss");
         }
 }





More information about the Chicago-talk mailing list