Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Perl (http://www.programmingforums.org/forum21.html)
-   -   Script problem or platform conversion error (http://www.programmingforums.org/showthread.php?t=10861)

kruptof Jul 27th, 2006 2:30 PM

Script problem or platform conversion error
 
i wrote this script on my windows box:
:

use CGI;
$results=new CGI;

$comment=$results->param("comments");
$name=$results->param("name");
open(DAT,">>Comments.txt");
$i=60;
$j=0;
$szlen=length $comment;
print DAT $name;
print DAT "\n";

if($szlen<60)
{
        print DAT $comment."\n";
}
else
{
       
        while($i<=$szlen)
        {
                print DAT substr($comment,$j,$i)."\n";
                $j=$i;
                $i+=60;
        }
        if($i<$szlen)
        {
                print DAT substr($comment,$i,$$szlen-$i)."\n";
        }
}
close(DAT);

print "Content-type:text/html\n\n";


and i uploaded to my hosting company's linux server, but instead of getting a newline were i was expecting a new line i got this small rectangle between the texts, for example this the output on my windows box:
:

Test
Test


and this is the output on my server's linux box:
:

Test
Test

even when i type it in here it converts to a newline...any ways this is how the above is supposed to look "Test [] Test" (something like that). So
can some please tell me why this is. I thank you in advance for your replies.

kruptof Jul 27th, 2006 5:17 PM

Redirect Problem
 
okay after some googling and alot of cursing and head scatching i found an alternative to this problem, which seemed to help, so decided to test this, so halfway through my testing i said "i wonder if i refresh the page what would happen", well i found out, it wrote to the file again and the same thing was outputted twice, then i thought how about i redirect the user to another page, so i tried, but no matter what page i redirected the user to i ke getting the 404 page not found page, i even tried using full paths, but still 404,does any body know what on earth is happening here, any help is greatley appreciated.

Regards, Kruptof

Arevos Jul 28th, 2006 9:26 AM

Windows uses "\r\n" as its linebreak. Linux and other Unix-like systems use "\n". A simple substitution should convert between the two (s/\n/\r\n/g).

As for the redirect - can I see your redirection code?

kruptof Jul 28th, 2006 12:32 PM

thanks Arevos......................ok here is the code for the redirection.....no matter what address i put in i will always get the 404 error:
:

#!/usr/bin/perl
use CGI;
$results=new CGI;

$comment=$results->param("comments");
$name=$results->param("name");
open(DAT,">>Comments.txt");
$i=60;
$j=0;
$szlen=length $comment;
print DAT $name."<br>";
print DAT "\n";

if($szlen<60)
{
        print DAT $comment."<br>";
}
else
{
       
        while($i<=$szlen)
        {
                print DAT substr($comment,$j,$i)."<br>";
                $j=$i;
                $i+=60;
        }
        if($i<$szlen)
        {
                print DAT substr($comment,$i,$$szlen-$i)."<br>";
        }
}
close(DAT);
open(DAT,"Comments.txt");
my @cont=<DAT>;
close(DAT);
print "location: home.html"; #<- this is the RELOCATion PART
print "Content-type:text/html\n\n";


Arevos Jul 28th, 2006 12:40 PM

Try:
:

  1. print "Status: 302 Moved\nLocation: $url";

Where $url is the URL you wish to which you wish the user to be redirected.

kruptof Jul 28th, 2006 1:01 PM

still gettting the same error, here is the new code:
:

#!/Perl/bin/perl
use CGI;
$results=new CGI;

$comment=$results->param("comments");
$name=$results->param("name");
open(DAT,">>Comments.txt");
$i=60;
$j=0;
$szlen=length $comment;
print DAT $name."<br>";
print DAT "\n";

if($szlen<60)
{
        print DAT $comment."<br>";
}
else
{
       
        while($i<=$szlen)
        {
                print DAT substr($comment,$j,$i)."<br>";
                $j=$i;
                $i+=60;
        }
        if($i<$szlen)
        {
                print DAT substr($comment,$i,$$szlen-$i)."<br>";
        }
}
close(DAT);
open(DAT,"Comments.txt");
my @cont=<DAT>;
close(DAT);
$url="/test\.html";
print "Status: 302 Moved\nLocation: $url";
print "Content-type:text/html\n\n";


kruptof Jul 28th, 2006 1:30 PM

after some googling and some trails and errors i have found this:
:

print "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 3.2//EN'>";
print "<html><head><title>$page_title</title>";
print "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=http://www.somedomain.com'>";
print "</HEAD><BODY></BODY></HTML>";


there is still some thing wrong with this html but i will post that in the html forum.......thank you everyone for the help.

Arevos Jul 28th, 2006 1:50 PM

What happens if you put the full URL in? And what happens when you go to said URL normally?

kruptof Jul 28th, 2006 2:34 PM

i got an error 404

Arevos Jul 28th, 2006 2:38 PM

In both cases? Then surely it's nothing to do with the redirect script, but because the URL you're going to does not exist.


All times are GMT -5. The time now is 10:12 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC