Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Same program - 2 different results!

Status
Not open for further replies.

mpalmer12345

Programmer
Feb 16, 2004
59
US
Same program - 2 different results!

I am puzzled why I am getting two different results with the exact same program! The only difference is that one is being run on my home computer and the other is on the Web.

$text = '<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF">
<div align="center">
<table width="47%" border="0" align="center">
<tr>
<td width="16%">
<div align="right"><b><font><i>URL</i></font></b></div>
';

$text =~ s/\n/g;

my $txxx = "";
my $flag = 1;

while ($flag < 3) {
print "$txxx\n";
print "xxxxxxxxxxxxxxxxxxxx\n";
$flag += 1;
$text =~ s/<(.+?)>(.*)/$2/g;
$txxx .= "<$1>";
}
$text = $txxx;

print "$text\n";

#

The program on my computer gives

xxxxxxxxxxxxxxxxxxxx
<html>
xxxxxxxxxxxxxxxxxxxx
<html><head>

which is what I want.

But the program though CGI and this added code at the top
#!/usr/bin/perl
use LWP::Simple;
use CGI;
my $cgi = new CGI;
my $url = $cgi->param("urlval");
my $text = get($url);
print "Content-type: text/html\n\n";

gives

xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx

I am pretty sure the command

$text =~ s/\n//g;

is the source of the problem since when I take it out the result is a match -- but it's not the right results. I don't know how else to remove the line breaks from the original text that would make the problem go away.
 
If your home computer is windows you need to substitute for

\r\n (maybe \n\r, I always forget, try them both)

not just \n

Windows uses different line feeds then the rest of the universe.

I think that was your question, you say 'its not the right results' but I am not sure what you mean by that.
 
it's \n\r or \n\n\r (either one, windows isn't consistent)

also your search and replace command s// is missing a slash so you might want to do this:

Code:
$text =~ s/\n\r//g; # As you suspected palmer
#or
$text =~ s/\n\n\r//g;

you could do both if you'd like i don't think it will hurt anything.
 
Thanks! Actually, I found the problem elsewhere. The info was there in the second version after all, but was hiding in the html code the program tried to create from the result. "View source" revealed the hidden code.

Looking back, I see what a blindingly stupid question it was! I hope, though, that I am becoming less and less clueless every day, thanks to you guys.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top