Perl: Two different outputs as to whether a file exists

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
bsprogs
Forum Newbie
Posts: 21
Joined: Mon Apr 23, 2007 1:07 am

Perl: Two different outputs as to whether a file exists

Post 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?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

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

Post 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.
Post Reply