Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Re: Determine when file is done being written?

by EyeOpener (Scribe)
on Jun 12, 2002 at 20:24 UTC ( [id://173994]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-26 00:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found