#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11164885 use warnings; use Path::Tiny; #one.pl my $file = '/dev/shm/tmpcount.txt'; for (1 .. 180) { print "$_\n"; # &filewrite($file,$_); path($file)->spew($_); # NOTE writes to temp file, then atomic renames over sleep 1; } #two.pl my $file = '/dev/shm/tmpcount.txt'; my $c; do { if (-e $file) { # $c = &fileread($file); $c = path($file)->slurp; die "C is empty" unless ($c); print "count is $c \n"; } else { print "File not found\n"; } } until ($c == 180);