Page 1 of 1

Perl: Two different outputs as to whether a file exists

Posted: Fri May 02, 2008 11:33 am
by bsprogs
I've been programming PHP for a few years but my employer now wants me to learn Perl as well.

This is a simple perl script that checks to see if a file exists. The file is in the same directory as the perl script below. The script is simple and straightforward but it's the results that aren't making sense to me.

Code: Select all

 
#!/usr/bin/perl 
 
print "Content-type: text/html\n\n"; 
 
$file = "ccv.html"; 
 
if (-e "$file"){ 
    print "File exists"; 
} else { 
    print "File doesn't exist for some reason"; 
}
 
Here is where I'm lost.

Browser Output: "File doesn't exist for some reason"

SSH output: "File exists"

So when I run "perl perlfile.pl" via SSH it says the file exists. However, the browser output says otherwise.

Any thoughts?

Re: Perl: Two different outputs as to whether a file exists

Posted: Fri May 02, 2008 12:40 pm
by califdon
bsprogs wrote:I've been programming PHP for a few years but my employer now wants me to learn Perl as well.

This is a simple perl script that checks to see if a file exists. The file is in the same directory as the perl script below. The script is simple and straightforward but it's the results that aren't making sense to me.

Code: Select all

 
#!/usr/bin/perl 
 
print "Content-type: text/html\n\n"; 
 
$file = "ccv.html"; 
 
if (-e "$file"){ 
    print "File exists"; 
} else { 
    print "File doesn't exist for some reason"; 
}
 
Here is where I'm lost.

Browser Output: "File doesn't exist for some reason"

SSH output: "File exists"

So when I run "perl perlfile.pl" via SSH it says the file exists. However, the browser output says otherwise.

Any thoughts?
My first guess is that it's a path issue. Where is "ccv.html"? If it's in the same path that you execute your ssh perl script from, it can find it, but if that's not in the same path as your web server document root, then the web can't find it. Try using a fully qualified path/filelname.