jeffpflueger has asked for the wisdom of the Perl Monks concerning the following question:

I need help simply deleting a file:

#!/usr/bin/perl; use warnings; use strict; unlink addgear.htm; exit;
That's what I've got....trying to keep it real simple until I figure out how to do this. The error I get from perl is:
bash: ./deletefile.cgi: No such file or directory
The error I get from my error log is:
failed to open log file fopen: Permission denied
addgear.htm exists and is in the same directory as deletefile.cgi (this little script) So I've tweeked with permissions and think that this is my problem...but I don't know. Any help would be great.

Thanks!

Replies are listed 'Best First'.
Re: Simply Deleting a File
by btrott (Parson) on Mar 02, 2001 at 06:58 UTC
    No, the real problem here is that your #! line is wrong. You have a semicolon at the end. It should be:
    #!/usr/bin/perl
    The error message you're getting is from your *shell*, not from Perl.

    Of course, it's also true that you need to quote your filename that you're passing to unlink, and that you need to add some error checking on unlinking the file.

      YES! The old semi-colon. That was the problem. Thank you! I often get in problems for not having one, this is the first time I had problems for having one. Thanks all for your help and input!

Re: Simply Deleting a File
by japhy (Canon) on Mar 02, 2001 at 05:41 UTC
    Quote the filename. unlink "addgear.htm" or die "can't unlink addgear.htm: $!";

    japhy -- Perl and Regex Hacker
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Simply Deleting a File
by BlueLines (Hermit) on Mar 02, 2001 at 05:40 UTC
    Either add a full path to the file name (ie '/home/jschatz/foo.htm') or use chdir. I'm not seeing where in your code a logfile is being opened, but that's a definite permission problem. Make sure you have write permissions there....

    BlueLines

    Disclaimer: This post may contain inaccurate information, be habit forming, cause atomic warfare between peaceful countries, speed up male pattern baldness, interfere with your cable reception, exile you from certain third world countries, ruin your marriage, and generally spoil your day. No batteries included, no strings attached, your mileage may vary.