in reply to Re: Repeated lines
in thread Repeated lines

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

Replies are listed 'Best First'.
Re: Re: Re: Repeated lines
by chipmunk (Parson) on Dec 23, 2000 at 01:55 UTC
    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.)