in reply to Repeated lines

I'm not sure why your code behaves this way when executed as a CGI script (I'd want to see more of the code to figure that out), but I will point out that you are not using the right content-type. You're printing a content-type of text/html, when your content is actually text/plain.

Replies are listed 'Best First'.
Re: Re: Repeated lines
by Anonymous Monk on Dec 23, 2000 at 01:48 UTC
    Here is the entire code.. The code works.. It's just that fact that it seemingly executes twice via a web browser like I mentioned before.
    #!/usr/bin/perl <BR> use Lingua::Ispell;<BR> print "Content-type: text/plain\n\n";<BR> print "beginning\n\n";<BR> $line="delte five";<BR> spellit();<BR> sub spellit<BR> {<BR> $spellline=$line;<BR> $realine=$line;<BR> for my $r ( Lingua::Ispell::spellcheck($spellline) ) {<BR> print "right after <BR>$spellline\n ";<BR> if ( $r->{'type'} eq 'miss' ) {<BR> print "$r->{'term'}";<BR> } <BR> } <BR> }<BR>
    This is the output via web browser activation:
    beginning Content-type: text/plain beginning right after delte five delte


    Output after running via command prompt:
    beginning Content-type: text/plain beginning right after delte five delte
      I'm a little confused... In your original post, you said that, when run as a CGI, the program output everything twice. But in the sample output you posted in your second node, you show Content-type: text/plain beginning output twice, but the list of mispelled words output only once.

      If the latter is the case, then I suspect that Lingua::Ispell is forking off a subprocess to handle the spell-checking, before the output buffers have been flushed, and so everything that was printed before the fork gets output twice.

      The solution is to turn on autflushing, by setting $| = 1 at the top of your program, before you print anything.

      (I believe that the latest version of Perl avoids this problem by automatically flushing output buffers when it's about to fork.)