'\n' & <br> problem

N

Nikos

if( param('select') ) {
$data = open_script( $host, param('select') );
} elsif( $match ) {
$data = welcome_old( $host );
} else {
$data = welcome_new( $host );
}


sub welcome_old {
my ($host) = @_;

$dbh->do( "UPDATE guestlog SET hostcount = hostcount + 1 WHERE
host='$host'" );

my $sth = $dbh->prepare( "SELECT * FROM guestlog WHERE
host='$host'" );
$sth->execute();
my $row = $sth->fetchrow_hashref;

return "Êáëþò Þëèåò " .$host. "! ×áßñïìáé ðïõ âñßóêåéò ôçí
óåëßäá åíäéáöÃñïõóá!\n".
"Ôåëåõôáßá öïñÜ Þñèåò åäþ ùò " .$row->{host}. " óôéò "
..$row->{date}. " !!\n".
"ÓýíïëéêÃò Þñèåò åäþ " .$row->{hostcount}. " öïñÃò !!!\n".
"Ôåëåõôáßá åßäåò ôï êåßìåíï { " .$row->{script}. " }\n".
"Ãïéü êåßìåíï èá ìåëåôÞóåéò áõôÞí ôçí öïñÜ !?";
}

When i have '\n' then my script print blank lines, if i change it to
<br> it does not, why?

Also i have to use these if i want my script to print ok the fiel it
opens. maybe i dotn have to when <br> works!

$data =~ s/\n/\\n/g;
$data =~ s/"/\\"/g;
$data =~ tr/\cM//d;
 
N

Nikos

Nikos wrote:

The $data then would pass to the index.html which is a template file and
then $data would be printed by javascript like this:

var textToShow = "<TMPL_VAR name=data>";

So if it contains chars like ' or " or \ or / that would be a problem right?

At least in my old index.pl (the one with cgi.pm) there was problem
printing it.

What can i do?
 
G

Gunnar Hjalmarsson

Nikos wrote:

return "Êáëþò Þëèåò " .$host. "! ×áßñïìáé ðïõ âñßóêåéò ôçí
óåëßäá åíäéáöÃñïõóá!\n".
"Ôåëåõôáßá öïñÜ Þñèåò åäþ ùò " .$row->{host}. " óôéò "
.$row->{date}. " !!\n".
"ÓýíïëéêÃò Þñèåò åäþ " .$row->{hostcount}. " öïñÃò !!!\n".
"Ôåëåõôáßá åßäåò ôï êåßìåíï { " .$row->{script}. " }\n".
"Ãïéü êåßìåíï èá ìåëåôÞóåéò áõôÞí ôçí öïñÜ !?";
}

When i have '\n' then my script print blank lines, if i change it to
<br> it does not, why?

The code you posted doesn't print anything AFAICS.

Nikos, you seem to try using this group as a substitute for own
studying. As you should have understood by now, that's not appreciated.

Please take a step back and start reading about the basics of HTML and
CGI. As regards CGI scripts in Perl, you can find a few online tutorials
at http://cgi.resourceindex.com/Documentation/CGI_Tutorials/

When you come back here, please respect the posting guidelines and try
to express yourself clearly. For instance, if a program does not behave
as you had expected, write a *small* but *complete* program that
illustrates just that behaviour (i.e. don't post a lot of code that
irrelevant to the problem in question).

If you do so, you'll be welcome to ask questions here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top