Gossamer Forum
Home : General : Perl Programming :

Weird problem...help!!

Quote Reply
Weird problem...help!!
Hi,

I have this at the top of my script somewhere:

if ($FORM{'vars'} eq "yes") {
open(MSG,">$basepath/$baseindex/mtemp.dat") | | die $!;
print MSG "$FORM{'message'}";
close(MSG);
}

open(MSG,"$basepath/$baseindex/mtemp.dat") | | die $!;
@newmessage = <MSG>;
close(MSG);

now, when I try this:
print FILE2 "(n/t)" unless @newmessage ne "";


it won't print (n/t) even if it is empty.

any suggestions?


Brett
Quote Reply
Re: Weird problem...help!! In reply to
At the very least, I don't see where you're opening a file with the filehandle FILE2 to print to.

--mark
Quote Reply
Re: Weird problem...help!! In reply to
Hi,

Well, thats because I did'nt post the whole bit of that code area. Below is more detailed:

open(FILE2,">>$basepath/$basedir/databoard.dat") &#0124; &#0124; die $!;

print FILE2 "<ul><li>\n";
print FILE2 "<b><a href=\"$URL/$baseindex/$messages/$count.$pages\">$FORM{'nsubject'}</a></b>";

print FILE2 "(n/t)" unless @newmessage ne "";

print FILE2 " - $months[$mon] $daym, $year\n";
print FILE2 "<!-- $count -->\n";

print FILE2 "</ul>\n";
print FILE2 "<p>\n";

CLOSE(FILE2);


Brett
Quote Reply
Re: Weird problem...help!! In reply to
This code:

print FILE2 "(n/t)" unless @newmessage ne "";

bothers me.

@newmessage ne "" is a SCALER context.

That means that when evaluated, @newmessage is going to return an integer value of the number of elements in the array, or possibly undefined (I don't do things like this enought to know for sure).

Try

@newmessage eq '0'

as the test, and see what happens, or completely rewrite the test to handle the condition you are trying to evaluate.

Maybe something like if $newmessage[0] eq "" which would check to see if the first element of @newmessage was null.

Quote Reply
Re: Weird problem...help!! In reply to
Thanks it works now.

I put this:

if (@newmessage eq "0") {
print FILE2 "(n/t)";
}


Brett