perl help... for real this time!

gopunk

Lifer
Jul 7, 2001
29,239
2
0
i know, my past 2 perl help threads were tards, but this one is for real i swear...


here is the code:

#!/usr/local/bin/perl

# assign date/time to variables
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

print "Content-type: text/html\n\n";
$filename = "$mon.dat";
$path = "/dw08/d20/mssug/cgi-bin/test";

print <<EOF;
<HTML>
<HEAD><TITLE>Hello, world!</TITLE></HEAD>
<BODY><H1>
EOF

open (OUTFILE, ">$path/$filename");


if (-e $path/$filename){
print <<EOF;
Hello, world!
EOF
}


else {
print <<EOF;
$path/$filename does not exist!
EOF
}

print <<EOF;
</H1></BODY>
</HTML>
EOF




the problem is this, for whatever reason, the conditional i have for the if statment is not working. the file exists, but the script still goes to else, and prints "so and so does not exist!"

it works fine if i just use $filename instead of $path/$filename, but why? shoudln't the latter work as well?
 

BigJohnKC

Platinum Member
Aug 15, 2001
2,448
1
0
Is your path starting from the root directory? The directory "dw08" is directly under the root "/"? Sure you spelled it right? ;)
Using absolute pathnames is dangerous in programming, I usually stick with the relative paths or use some sort of a configuration file. Well, not really dangerous, but it makes it so you have to go back into the code if you ever change the location of the file.
 

gopunk

Lifer
Jul 7, 2001
29,239
2
0


<< Is your path starting from the root directory? The directory "dw08" is directly under the root "/"? Sure you spelled it right? ;)
Using absolute pathnames is dangerous in programming, I usually stick with the relative paths or use some sort of a configuration file. Well, not really dangerous, but it makes it so you have to go back into the code if you ever change the location of the file.
>>



yup, it is, i can copy and paste it after cd, and it goes there... as it should... after all i did get it orignally from pwd :)

yea, hopefully i can do the config file eventually... right now i'm just trying to get the basics down (perl newbie).

so shoudl this work? i can't for the life of me figure out why it's not working... the weird thing is that just $filename works... so it's the $path part that's tripping it up :(