whitespace and perl....

gopunk

Lifer
Jul 7, 2001
29,239
2
0
is whitespace in the code an issue? i only ask because when i tab EOF, it breaks the code, but when there is no leading whitespace, it works fine. just wondering what could be causing this. thanks!
 

Mitzi

Diamond Member
Aug 22, 2001
3,775
1
76
Whitespaces shouldn't cause any problems (unless its part of a string, obviously).

Can you give more info about the problem? Are you trying to detect the EOF for a data file you are reading/writing too? Can you give a code snippet?
 

gopunk

Lifer
Jul 7, 2001
29,239
2
0
yea sure:




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

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


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

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




if i tab the EOF's at the end of each print thing, weird things happen. if i tab the one at the end of the first, third, or fourth one, i get an internal server error. if i tab the one at the end of the second one, i get a blank page with the correct page title.
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
it is only an issue if you are using it the way you are (printing multiple lines).
this is also true for shell scripts

the thing is, the print for multiple line is looking for the ending mark (in your case, the "EOF")
with it not at the first column of the line, the print will think that it's not the EOF that you are looking for, and will just disregard it and moving along... until you reach the end of your script, it still haven't found the corresponding EOF, and your code will bomb out ...

btw, the internal server error you are getting is because the cgi handler (i'm assuming you are writing this for cgi script) gets an error message from the perl interpreter of your web server. since it doesn't know how to handle perl errors, it gives you internal server error....

-949-