develooper Front page | perl.beginners | Postings from January 2002

Re: What's wrong with this?

Jeff 'japhy' Pinyan
January 24, 2002 13:39
Re: What's wrong with this?
Message ID:
On Jan 24, Eduardo Cancino said:

>The next script runs looks pefectly in IE but in Netscape it shows the
>source of the html...

That is because IE does things that a browser should not do.

># recibe la forma.
>read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>@pairs = split(/&/, $buffer);

Ugh.  You should not try to deal with incoming form information yourself
-- use the standard module.  Please.

># inicia variables.
>$to = "info\";
>$from = "info\";
>$subject = "Comentarios Sitio Web";
># manda el mail.
>open (MAIL,"|mail $to");
>print MAIL <<"END_top";
>"To: $to
>Reply-To: $to:
>Subject: $subject"

That's not working, I can promise you that.

  print MAIL << "END_top";
  To: $to
  Reply-To: $to
  Subject: $subject


Notice I didn't quote the surrounding text.

>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;
>   if ($form{$name} ne "" && $form{$name} ne "no" && $name ne 'enviar') {
>      print MAIL $name . " = ". $form{$name} . "\n";
>  }

This is bad too.  Use  Please.

>close MAIL;
># imprime html.
>print <<WEB_page;
>Content-type: text/html
><!doctype html public "-//w3c//dtd html 3.2 final//en">

Here's the primary problem.  You cannot place a newline before the HTTP
headers, and you MUST place an extra newline AFTER the HTTP headers.

  print << "WEB_page";
  Content-type: text/html

  <!doctype ...>

Notice the difference?

Jeff "japhy" Pinyan
RPI Acacia brother #734
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course. Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About