Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Determine when file is done being written?

by Weasel (Sexton)
on Jun 12, 2002 at 18:18 UTC ( [id://173951]=note: print w/replies, xml ) Need Help??


in reply to Determine when file is done being written?

trapping an error is easy:
eval { # your code to be trapped # ... or die "error message 123" } if ($@) { # do your error checking, such as $@=~/error message 123/ }
As was announced perl6 will change "eval{BLOCK}" to "try{BLOCK}" when it is used for trapping an error, to be more consistent.

It is interesting though to have a possibility to check whether writting is currently performing.

I think it is somewhere in IO::* modules (may be in IO::Handle), but unfortunately can not help with this right now.

Have a nice day,
Weasel.

Replies are listed 'Best First'.
Re: Re: Determine when file is done being written?
by EyeOpener (Scribe) on Jun 12, 2002 at 20:24 UTC
    Thanks Weasel and everyone for the suggestions. The eval in a bare block turned out to be a nice, simple solution, and lets me catch more than just the possible error I know about:

    sub dostuff { my $victim = shift; { eval { open IN, "$victim" or die "Can't open the file: $!\n"; }; last unless $@; if ($@ =~ /containing a running program/) { print " Waiting...\n"; sleep 5; redo; } else { die "Unknown error opening file: $@"; } } # more stuff here close IN; rename "$victim", "/z/saved/$victim"; }

    I'll have to get comfy with eval; I can see how it could be indispensable. Thanks again!

    Peter

      Let me add little comment to save you from possible problem.

      Actually eval("string") would be much slower than eval{BLOCK} because in first case Perl will parse it every time statement is executed, while second form will be compiled once, and actually it is a replacement for "try".

      Best wishes,
      Weasel.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-20 02:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found