On Wednesday 23 Oct 2002 1:47 pm, Octavian Rasnita wrote: > Hi all, > > I want to create an if statement like: > > if (-e $file) { > for($i = 0; $i < 10; $i++) { > sleep(1); > } > unlink $file; > } > > Please tell me what will happen if in this period of time (10 seconds) > another page visitor, or program will delete $file. > > Will this script try to delete a non existent $file? > > Will the script check the if statement for each function under it, so it > will see that there is no $file, or I should use: > unlink $file if -e $file;
if (-e $file) { for($i = 0; $i < 10; $i++) { sleep(1); } unlink $file; } The if statement controls access to the block following it. The condition is only checked once, so the answer to the first part is yes - if another program deletes the file within the 10 seconds your script will try to delete a non-existant file. unlink $file if -e $file; This will do what you want, and if another prog does delete the file in during the sleep the unlink won't be called. BTW, why do you want the 10 second pause anyway? Also, why don't you simply use 'sleep 10' instead of creating the loop? > > Thanks. > > Teddy's Center: http://teddy.fcc.ro/ > Email: [EMAIL PROTECTED] -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]