Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > premature end of script headers

Reply
Thread Tools

premature end of script headers

 
 
Raistlin Majere
Guest
Posts: n/a
 
      05-03-2006
print "Content-type: text/html\n\n";

open(OLDLIST, "<link list.txt");
open(NEWLIST, ">link list.tmp");

$count=1;

$line1="";
$line2="";

foreach $line(<OLDLIST>)
{
chomp($line);

if($count==1)
{
$line1=$line;
};

if($count==2)
{
$line2 =~ s/Suggested Text/$line1/;

print NEWLIST $line2."\n";
};

if($count==3)
{
$count=0;
};

$count++;
};

close(NEWLIST);
close(OLDLIST);

# what is wrong?

 
Reply With Quote
 
 
 
 
David Squire
Guest
Posts: n/a
 
      05-03-2006
Raistlin Majere wrote:
> print "Content-type: text/html\n\n";
>

....

For a start, what is in the error log on the web server that reported
"premature end of script headers". That should give you a clue as to
what went wrong.

After that, you script has:

- no shebang line (#!/usr/bin/perl)
- no "use strict;"
- no "use warnings;"
- an unquoted (\Q) variable in a substitution
- if's that should be elsif's

Still, my first guess would be the lack of a shebang line. Can your web
server (Apache?) even find perl, or know that this is a Perl script?

DS
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      05-03-2006
Raistlin Majere wrote:
> print "Content-type: text/html\n\n";
>
> open(OLDLIST, "<link list.txt");
> open(NEWLIST, ">link list.tmp");

<SNIP>
> # what is wrong?


What happened when you tried to run this program on the command line,
by just typing the path to the file (ie, not preceding it with 'perl')
? Did it work as you expect? (Hint: NO, it did not.) Why not?

Paul Lalli

 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      05-03-2006
"Raistlin Majere" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) oups.com:

#!/usr/bin/perl

use strict;
use warnings;

missing

> print "Content-type: text/html\n\n";
>
> open(OLDLIST, "<link list.txt");


Always, yes, always check if the open call succeeded.

What do you think this call is supposed to do?

> open(NEWLIST, ">link list.tmp");


Ditto.

>
> $count=1;
>
> $line1="";
> $line2="";
>
> foreach $line(<OLDLIST>)


By using the for loop, you have already slurped the whole file. Then you
go and process it line-by-line. Do it right from the get go:

while ( my $oldline = <OLDLIST> ) {
chomp($oldline);

> if($count==1)
> {
> $line1=$line;
> };


Perl already has a builtin variable keeping track of the line count.
Read perldoc perlvar for $.

>
> if($count==2)
> {
> $line2 =~ s/Suggested Text/$line1/;



Where is $line2 initialized?

>
> print NEWLIST $line2."\n";
> };
>
> if($count==3)
> {
> $count=0;
> };
>
> $count++;
> };
>
> close(NEWLIST);
> close(OLDLIST);
>
> # what is wrong?


Many things. Make sure that the program works from the command line
before trying it as CGI.

I think this is what you are trying to do:


#!/usr/bin/perl

use strict;
use warnings;

my ( $suggestion );

while ( <DATA> ) {
chomp;
if ( $. % 2 ) {
$suggestion = $_ if $. % 2;
} else {
s/Suggested Text/$suggestion/g;
print $_, "\n";
}
}

__DATA__
read
I will Suggested Text the posting guidelines
help
Posting guidelines Suggested Text me Suggested Text myself,
help
and Suggested Text others Suggested Text me.

C:\Home\asu1\src> perl t.pl
I will read the posting guidelines
Posting guidelines help me help myself,
and help others help me.

C:\Home\asu1\src>
 
Reply With Quote
 
Raistlin Majere
Guest
Posts: n/a
 
      05-03-2006
Thank you all, but I solved the problem. I was trying to write...

#!C:\Programas\xampplite\perl\bin\perl.exe

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

open(OLDLIST, "<link list.txt");
open(NEWLIST, ">link list.tmp");

$count=1;

$text="";
$link="";

foreach $line(<OLDLIST>)
{
chomp($line);

if($count==1)
{
$text=$line;
};

if($count==2)
{
$_ = $line;

s/Suggested Text/$text/;

$link = $_;

print NEWLIST $link."\n";
};

if($count==3)
{
$count=0;
};

$count++;
};

close(NEWLIST);
close(OLDLIST);

 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      05-03-2006
"Raistlin Majere" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) oups.com:

> Thank you all,


Thank us for what? Please quote some context.

> but I solved the problem.


What problem did you solve?

> I was trying to write...
>
> #!C:\Programas\xampplite\perl\bin\perl.exe


That was only a minor issue.

The whole program is a problem. At this rate, you will cause many, many
headaches to a great many people.

Sinan
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows cgihandler Error: Premature end of script headers Kevin Layman Ruby 3 05-21-2009 11:59 PM
Re: premature end of script headers Phil Frost Python 0 07-10-2004 03:24 AM
'Premature end of script headers' error when starting Apache inboot time Greeshma Python 1 02-27-2004 08:19 AM
'Premature end of script headers' error when starting Apache inboot time Greeshma Python 0 02-25-2004 04:44 AM
Premature end of script headers Wayne Deleersnyder Perl 1 11-21-2003 01:00 PM



Advertisments