Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Perl/cgi Help!, HTML skills required also.
Izlude
post Apr 10 2005, 10:59 PM
Post #1


Newbie [Level 2]
**

Group: Members
Posts: 34
Joined: 3-April 05
From: Puerto Rico
Member No.: 5,230



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 ...
Go to the top of the page
 
+Quote Post
Hamtaro
post Apr 11 2005, 01:57 AM
Post #2


Super Member
*********

Group: Members
Posts: 372
Joined: 14-October 04
Member No.: 1,736



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.
Go to the top of the page
 
+Quote Post
vizskywalker
post Apr 13 2005, 10:44 PM
Post #3


Member [Level 2]
*****

Group: Members
Posts: 79
Joined: 12-January 05
Member No.: 3,251



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
Go to the top of the page
 
+Quote Post
Izlude
post Apr 16 2005, 10:26 PM
Post #4


Newbie [Level 2]
**

Group: Members
Posts: 34
Joined: 3-April 05
From: Puerto Rico
Member No.: 5,230



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
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Perl Help(1)
  2. First Perl Programm(5)
  3. Second Perl Programm(0)
  4. Perl Programms(0)
  5. Perl Programming(0)
  6. Using Mysql With Perl(1)
  7. Perl V.s. Php(5)
  8. Easy Authenication With Cgi/perl(0)
  9. Perl Progamming/scripting(3)
  10. Perl Interview Questions(1)
  11. Compiling Perl / Python?(3)
  12. Xmlhttprequest And Perl(2)
  13. Matching Accents In Perl Regular Expresions(1)
  14. Call C Code From Perl(1)
  15. Few Perl Snippets For Misc Things(2)
  1. What Is Perl ? For A Layman Like Me !(7)
  2. Where Do I Install Perl Scripts?(6)
  3. Perl As A Way To Program Desktop Applications(8)
  4. Perl Interactive Mode(2)


 



- Lo-Fi Version Time is now: 27th July 2008 - 02:09 AM