Nov 21, 2009

Perl/cgi Help! - HTML skills required also.

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > Perl Programming

Perl/cgi Help! - HTML skills required also.

Izlude
Im sort of new with perl and I know the basics. Lemme paste the code ...

CODE

#!/usr/bin/perl -w

if ($ENV{'REQUEST_METHOD'} eq 'POST') {

  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])<br>/pack("C", hex($1))/eg;
  $FORM{$name} = $value;
  }
 open (QUOTE, '>>logs.txt');
 print QUOTE "<center>$FORM{quote}<br><br>\n\n";
 print QUOTE "<hr width=20%></center><br><br>\n\n";
 close (QUOTE);
 &thx;
}
else {
 &error;
}


I have no problems with the subs .... I just want to end every line of text with a <br>. I have another perl script that reads the whole logs.txt file and pastes it into a HTML page. Can anyone help me?

Thanks in advance ...

 

 

 


Comment/Reply (w/o sign-up)

Hamtaro
Just to let you know: I quit using Perl/CGI about 2 or 3 months ago and started learning PHP, but I still remember some of it, so I'll try my best to help you.

I think you called the item in the array wrong.
I usually did: $FORM[Name] instead of $FORM{Name}
That could be the problem you're having. Have you checked your error logs for the problem? By the way it looks, the rest is fine.

Here's what I think should be fixed:
$ENV{'REQUEST_METHOD'} to $ENV['REQUEST_METHOD']
$ENV{'CONTENT_LENGTH'} to $ENV['CONTENT_LENGTH']
$FORM{$name} = $value; to $FORM[$name] = $value;
$FORM{quote} to $FORM[quote]

I hope that helps you.

Comment/Reply (w/o sign-up)

vizskywalker
First of all, I just checked all of my scripts, you had the correct format for an array, it is not necessarily $FORM['blah]. What do you mean by end with <br>. If you mean place the text "<br>" at the end of each line, simply place it in the end of each of your printed lines. That ought to work. If you tell us exactly what isn't working right we can provide better solutions.

~Viz

Comment/Reply (w/o sign-up)

Izlude
Thanks to you both for replying biggrin.gif

Well .. I did a mass debug of the script and found that the problem I was looking for was not there lol.

CODE

open(READ,"<logs.txt") or die "Could not connect to database.";
while (<READ>) {
$s = $_;
print "<br> $s";
 };

the $s was being written to logs.txt in separate lines (as plain text), but since the other script (logs.pl) prints $s in a HTML page, it never line break'd.


Also ... the <br> inside this line messed up the first script posted above:
CODE

$value =~ s/%([a-fA-F0-9][a-fA-F0-9])<br>/pack("C", hex($1))/eg;


Thanks again. laugh.gif

 

 

 


Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Perlcgi Help33 Html Skills Required


    Looking for perl, cgi, html, skills, required

Searching Video's for perl, cgi, html, skills, required
See Also,
advertisement


Perl/cgi Help! - HTML skills required also.

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com