I dont want the perl program to print \n on each line..

They have: 45 posts

Joined: Aug 2000

I am writing to an array, and then I have the program read each line of the array and split it. However, when the user (this is a guestbook) posts something and hits enter, perl prints out a newline in the guestbook file, making it hard to read each line as a new post. Is there anyway to make perl not print to a newline? I tried replacing each \n with a , but in the file the lines are still seperate. Unless, does perl not read a newline in the file UNLESS it says \n? Ok, this is hard, but any help would be great!

Laguna Loire
Site Director: Laguna's Jukebox (http://jukebox.3dstream.net)
Site Admin: RPGBoards (http://rpgboards.3dstream.net)

They have: 568 posts

Joined: Nov 1999

I think I understand what your saying.

Do this BEFORE you print the guestbook data to the file.

$form{'message'} =~ s/\n//g;

replace $form{'message'} with whatever the field is.

They have: 45 posts

Joined: Aug 2000

Ill try that, thanks.

They have: 193 posts

Joined: Feb 2000

What Orpheus suggested is very useful. However, if the person goes to a new paragraph, it won't work. Example:

Quote:
This is par one.

This is par two.

Last I knew his code won't handle that right.

Try this if it doesn't:

$var =~ s/\n\r\n/<br><br>/sg;
$var =~ s/\n/<br>/sg;
$var =~ s/\r/<br>/sg;
'

(The above is similar to what the UBB uses.)

Richard

[email protected]

Everyone here has a website. It's just that not all are worth posting (Mine! Smiling).

They have: 2 posts

Joined: May 2000

It might be useful if you posted the script Smiling

They have: 45 posts

Joined: Aug 2000

Here is the ENTIRE guestbook:

#!/usr/bin/perl
print "Content-type: text/html\n\n"; #content is html
##############################
# #
# Streamline Guestbook #
# v2.0 Beta #
# coded by: Josh Nylund #
# and Russ Klinkerman #
# ww2.3dstream.net #
# #
# #
# #
##############################

#get the varibles that are incoming!
if ($ENV{"REQUEST_METHOD"} eq "GET") {
$input = $ENV{QUERY_STRING};
@pairs = split /\&/ , $input;

foreach $pair (@pairs) {
($name,$value) = split(/=/,$pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$form{$name} = $value;
}
} else {
read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
@pairs = split(/&/,$buffer);
foreach $pair (@pairs) {
($name,$value) = split(/=/,$pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$form{$name} = $value;
}
}
$action = $form{'action'}; #what did the user want to do????
#/end getting varibles
#required files
require "vars.file";
require "badwords.file";
#end files

#check actions and do proper thing (action and if guestbook is on or off)########################################################
if($action eq ""){
if($bookstatus eq "on"){

$titleaction = "Welcome";

{&doheader;}{&domenu;}
print qq|

Welcome to $pagename guestbook! Please take a look at our guests' entrys, then add one of your own!

|;
{&dofooter;}{&dohits;}

} elsif ($bookstatus eq "off"){
$titleaction = "Guestbook Disabled";
{&doheader;}
print qq|

$pagename Guestbook is currently closed! Please come back soon!
|;
{&dofooter;}{&dohits;}
}
#post and entry! ##########################################################################
} elsif ($action eq "postentry"){
$titleaction = "Post Entry";
{&doheader;}{&domenu;}
print qq|

.: Name -

.: E-Mail Address -

.: Web Address -

.: Where do you live? -

.: Comments -
|;
if($usehtml eq "off") {
print "HTML in posts is disabled!\n";
} elsif ($usehtml eq "on" ) {
print "HTML in posts is enabled!\n";
} else {
print "Program Error, html checking not working, please contact the webmaster of this site!";
die
}
print qq|

|;
{&dofooter;}

##return the data for printing and checking! ##########################################################################
} elsif ($action eq "returnentry"){
$username = $form{'username'};
$userinfo = $form{'userinfo'};
$useremail = $form{'useremail'};
$userurl = $form{'userurl'};
$form{'comments'} =~ s/\n//g;
$comments = $form{'comments'};

#add an entry!

#add the date
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
@months = ("January","February","March","April","May","June","July","August","September","October","November","December");
@days = ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
$currentyear = $year + 1900;
$month = @months[$mon];
$day = @days[$wday];
$date = "$day, $month $mday, $currentyear";
#compile the data
if ($usehtml eq "off") {
$comments =~ s//.>/g;
}
if ($dobadwords eq "yes") {
foreach $badword (@badwords) {
$comments =~ s/$badword/****/ig;
}
}
#add length feature! length("whatever")
$useremail =~ s//gt;/g;
$username =~ s//gt;/g;
$userurl =~ s//gt;/g;
$userinfo =~ s//gt;/g;
$comments =~ s//- >/g;
$comments =~ s/\n//g;
$entryline = "$username|$date|$useremail|$userinfo|$userurl|$comments\n";
#print the entry
$titleaction = "Thank you for posting!";
{&doheader;}{&domenu;}
print "Thank you for posting! Please click 'view posts' to see your post!";
{&dofooter;}

open (guest, ">>book.file") || die "Cannot open file: $!\n";
flock(guest,2);
print guest "$entryline";
unlock(guest);
close (guest);

# {&dopost;} Not working!

##view the entrys! ##########################################################################
} elsif ($action eq "viewentrys"){
$titleaction="Viewing Entrys";
open (FILE, "book.file") || die "Cannot open file: $!\n";
@entrys = ;
close (file);

@entrys = reverse(@entrys);

{&doheader}{&domenu;}

open(counter, "counter.file") || die "Cannot open file: $!\n";
$counter=;
close(counter);
# print "Total Posts $counter"; not working!

foreach $linez(@entrys) {
$finalentry=$customstyle;
chomp($linez);
@linea = split(/\|/, $linez);

$finalentry =~ s//$linea[0]/ig;
$finalentry =~ s//$linea[2]/ig;
$finalentry =~ s//$linea[4]/ig;
$finalentry =~ s//$linea[3]/ig;
$finalentry =~ s//$linea[5]/ig;
$finalentry =~ s//$linea[1]/ig;
#print the data!
print qq|
$finalentry
|;

}
{&dofooter;}{&dohits;}
}

#subroutines
#header
sub doheader {
print qq|

$customhtmlstyles$pagename - $titleaction - Streamline Guestbook

<script language='javascript'>
=4 && (navigator.userAgent.toLowerCase().indexOf("mac")==-1)) {
document.write("");
document.write("");
} else {
document.write("");
document.write("");
document.write("
");
document.write("");
}
//-->
</script>


|;
}

#footer
sub dofooter {
print qq|

Powered by Streamline Guestbook2000 3Dstream Networks
|;
}

#html menu
sub domenu {
print qq|

.:Post an entry :
View entrys:.

|;
}

sub dohits {
open(hits, "hits.file") || die "Cannot open file: $!\n";
$hits = ;
close(hits);
$hits++;
open(hits, ">hits.file") || die "Cannot open file: $!\n";
flock(hits,2);
print hits "$hits";
unlock(hits);
close(hits);
}

sub dopost {
open(count, "counter.file")|| die "Cannot open file: $!\n";
$count=;
close(count);

$count++;
#print "$count";

open(count, ">counter.file") || die "cannot open file: $!\n";
flock(count,2);
print count "$count";
unlock(count);
close(count);
}

1;

Laguna Loire
Site Director: Laguna's Jukebox (http://jukebox.3dstream.net)
Site Admin: RPGBoards (http://rpgboards.3dstream.net)

They have: 45 posts

Joined: Aug 2000

I added that code. Looks like it worked! THANKS!

They have: 193 posts

Joined: Feb 2000

Which code? Smiling

Richard

They have: 45 posts

Joined: Aug 2000

Smiling yours!

They have: 193 posts

Joined: Feb 2000

Oh! You made my day!

Richard

They have: 429 posts

Joined: Jul 2000

Aww... they're getting along. Isn't that so cute.

Just..brings tears to my eyes.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.