in reply to Why aren't these equivalent?

I'm betting that you've got a permission problem, since you're probably not running the test script as the same user as the CGI script. This is one of the reasons you should check the return value of unlink(), open() etc and give a meaningful error message:
unlink( $fileName ) or die "Can't unlink $fileName: $!";

Replies are listed 'Best First'.
Re^2: Why aren't these equivalent?
by Anonymous Monk on Jul 12, 2008 at 00:54 UTC
    That was my first thought as well. But if it was a permission problem, then neither method would work. unlink() just returns the number of files unlinked, so it returns 1 for the snippet that works and 0 for the snippet that doesn't work, in this case.
      So it can't for some reason unlink the file. There are two possibilities: 1. you don't have permissions. 2. the path does not point to the right file (for instance, you're in the wrong current directory).

      So what's in "$!" ? I did not put that code there for laughs. Anyone who wonders why some operation on a file didn't succeed and doesn't do a check + print $! gets what (s)he deserves.

        Thanks for your suggestions Joost. I had already tried the die "......$!" before I posted my original message. It didn't help because I'm testing this on a web server, through a browser, and the page I'm generating just terminates at the point of error without reporting the error. I also don't seem to have access to the error_log on this particular (institutional) server.

        Tilly (see below) hit on the cause of the problem. Just to follow up on your suggestion, I ran the script from a command line and got another confirmation that it was the taint checking:
        Insecure dependency in unlink while running with -T switch at ./de +lete.cgi line 43.
        Thanks again.