Tony Marquis wrote:
I'm creating a script that open a directory. create a file call lock Work in the directory. delete the lock file and quit.
my ($rep_em) = "/test";
opendir (DIR, $rep_em) || die ("Error open directory $rep_em."); chdir($rep_em) || die ("Error change directory to $rep_em"); my @fic = readdir(DIR); open(LOCK , '>lock') || die ("Unable to create the lock file."); foreach (@fic) { if (!(($_ eq ".") || ($_ eq "..") || ($_ eq "lock"))) { printf ("%s \n", $_); } } close(DIR); unlink(LOCK) || die ("Unable to delete the lock file.");
I'm able to delete the file manually but when i run the script under the same user i get an error Unable to delete the lock file at line xx.
Thank for your help.
At least two things
closedir DIR or die "failed $!";
perldoc -f unlink doesn't take a file handle/glob LOCK, but a string 'lock'.
You should probably put the unlink in an END {} block so its always executed if you fail inbetween the locking for
a random reason.
--
END
------------------------------------------------------
Philip M. Gollucci ([EMAIL PROTECTED]) 301.254.5198
Consultant / http://p6m7g8.net/Resume/resume.shtml
Senior Developer / Liquidity Services, Inc.
http://www.liquidityservicesinc.com
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>