What are you actually trying to accomplish here though? Writing out files in the background whilst the script is running? Because it looks like the result of what you're trying to do, is to write 'aabbcc' to $tempfile and $file every 2s.
Without wanting to second guess too much, have you considered using threading? E.g.:
my $finished = 0 : shared; sub write_to_file { until ( $finished ) { open ( my $temp_fh, ">>", $temp_file ); print $temp_fh "aabbcc\n"; close ( $temp_fh ); } } #main bit of code here... $finished = 1; foreach my $thread ( threads -> list() ) { $thread -> join(); }
In reply to Re: The proper way to execute echo aabbcc >> file in backround
by Preceptor
in thread The proper way to execute echo aabbcc >> file in backround
by young_monk_love_perl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |