Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Random script crashes related to File::Copy

by tokpela (Chaplain)
on Apr 30, 2009 at 08:41 UTC ( #761061=note: print w/ replies, xml ) Need Help??

in reply to Random script crashes related to File::Copy

As others have mentioned above, this may be because the file has not yet finished writing. I would use a "stable" file concept and check that the file has not been modified since X time period.

# check if the file has stablized for over 30 seconds if (is_stable_file($file, 30)) { process($file); } sub is_stable_file { my $file = shift; my $wait_seconds = shift || 0; my $result = 1; if ($wait_seconds > 0) { my ($mtime) = (stat($file))[9]; my $secs_since_mod = (time - $mtime); if ($secs_since_mod < $wait_seconds) { $result = 0; } } return $result; }

Comment on Re: Random script crashes related to File::Copy
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://761061]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2015-12-02 01:43 GMT
Find Nodes?
    Voting Booth?

    My keyboard shows this many letters:

    Results (31 votes), past polls