in reply to Re: Determine when file is done being written?
in thread Determine when file is done being written?

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

Replies are listed 'Best First'.
Re: Re: Re: Determine when file is done being written?
by Weasel (Sexton) on Jun 12, 2002 at 20:50 UTC
    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.