Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax Question

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
The following code was working up until Monday this week.
Code:
if(-e $JPG_PICTURE){
print "1";
}else{
print "0";
}
The next section creates a web page and simply prints a picture with the name of $JPG_PICTURE.
The code above always evaluates as false and prints a 0 on the screen, then it prints the actual picture.
It appears that there is a problem with PERL with the ISP. Please confirm that the syntax is correct as my ISP says there is something wrong with the script.


Keith
 
Well, it appears to just be checking whether a file exists or not. Are you sure the file does not exist? Add this under print "1";

Code:
print STDERR "JPG_PICTURE: '$JPG_PICTURE' exists\n";

That will give you the path to the file, if that file's existence is a problem, maybe just move/delete it?

--jim
 
Added your code to the 1 option and nothing additional is printed.

This is part of a much more complex script but I have broken it down to its very basic form in the hope of finding out what is going wrong.

Code:
$JPG_PICTURE= ...... (Full Path to Picture)
# The picture does exist

	if(-e $JPG_PICTURE){
		print "1<br>";
	}else{
		print "0<br>";
# Prints 0 as if file not found
	}

# A bit of HTML to view the picture
print <<"test html";
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 2</title>
</head>
<body>
<p><img border="0" src=$JPG_PICTURE></p>
</body>
</html>
test html
exit;

Prints the picture I am expecting.



Keith
 
Then tried the same code as above with your code in both options and still nothing additional printed.
Code:
	if(-e $JPG_PICTURE){
print STDERR "JPG_PICTURE: '$JPG_PICTURE' exists\n";

		print "1<br>";
	}else{
print STDERR "JPG_PICTURE: '$JPG_PICTURE' exists\n";

		print "0<br>";
	}
My head is starting to hurt now.

Keith
 
Ah, this is a CGI script. The output is sent to STDERR, so check your log files. Or, just take out the STDERR part. I was thinking the STDOUT output was used for something else, like input to another program.

--jim
 
The problem seems to have been resolved.
The ISP has been moving files to new servers etc. and I think something had been destroyed/corrupted.
I didn't help the problem by my changing the original script to one which I now think, could never work. I had originally had a local reference to an images directory which stopped working on Monday. In my wisdom I had changed it to a full path reference.
It would seem that the -e function works locally but is unable to check files on a full http:// link.
A few experiments have shown this to be the case - worth remembering in the future.
Thanks for your help - it is always appreciated when someone takes the time to help for no reward.


Keith
 
Are you saying domain as in windows work groups? Or as in domain names for URL's? Judging by your earlier post where you mentioned http:// you are trying to do something like this:

if( -e " ){ ... }

And you are correct in thinking this will not work because "-e" is just a file test operator for files on the local filesystem.

If you need to see if a file exists on another server there are many ways to do that, is that what you are trying to do?

--jim
 
Another URL yes.
Not something I want to do at the moment but the thought came to mind when I was working out the subject of this post.
Why is it, the more we learn, the more we need to know.

Keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top