http://qs1969.pair.com?node_id=63398

SilverB1rd has asked for the wisdom of the Perl Monks concerning the following question:

I'm using something like this in a script and its is giving me a strang error why? the error is,
CGI Error The specified CGI application misbehaved by not returning a complete s +et of HTTP headers. The headers it did return are: Bareword "ONF" not allowed while "strict subs" in use at C:\webdev\www +root\cgi-bin\index.pl line 37. Execution of C:\webdev\wwwroot\cgi-bin\index.pl aborted due to compila +tion errors.
The code is like this.
use CGI; use strict; my ($q) = new CGI; my ($MyFile, $i, $t, $key, $NewRec); my (@Mfile, @Settings); $MyFile = "./data/data.txt"; open(INF, "< $MyFile") or dienice("Cant open file! Name of file: $MyFi +le"); seek(INF,0,0); @Settings = <INF>; close (INF); $i = @Settings[0]; $i =~ m/(\d+)/; $NewRec = "./data/scriptdata/R$1.txt"; sub somesub { open(ONF, ">$NewRec") or dienice("Cant open $NewRec"); $q->save(ONF); close (ONF); }
if I comment out the save(ONF); it works fine?

------
The Price of Freedom is Eternal Vigilance

Replies are listed 'Best First'.
Re: Why the error?
by merlyn (Sage) on Mar 10, 2001 at 03:29 UTC
    it means what it says. that's the wrong syntax. use
    $q->save(\*ONF);
    instead. Also, you should probably actually return a value somewhere, so that the CGI transaction is complete.

    -- Randal L. Schwartz, Perl hacker

      Thanks merlyn, that fixed it.
      <Warning>I'm new</Warning> what does the \* do?
      That is how they showed it in the CGI info page.

      ------
      The Price of Freedom is Eternal Vigilance
        In this instance, the "\*" basically returns a pointer to the filehandle. Something to do with typeglobs, an area I haven't explored much (yet). The asterisk indicates the typeglob (I believe), and the backslash performs it's usual "return-a-reference-to-this" function.

        A typeglob is basically a complete symbol table entry, but you can use them (and references to them) like file handles.

        Hot Pastrami
        \* is called a typeglob... if you are a beginner, this is way advanced for you to understand..
        in some words, this is a reference (and here a reference to a filehandle)
        the * is the typeglob.
        and the \ is to dereference it.
        a typeglob references anything from a $scalar, to an @array on to a FILEHANDLE
Re: Why the error?
by Masem (Monsignor) on Mar 10, 2001 at 03:34 UTC
    You probably also need a print $q->header in there somewhere...
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
Re: Why the error?
by converter (Priest) on Mar 10, 2001 at 13:36 UTC

    Take another look at your error message, and you'll see that there are two errors:

    The specified CGI application misbehaved by not returning a complete set of HTTP headers.
    and...
    Bareword "ONF" not allowed while "strict subs" in use at C:\webdev\wwwroot\cgi-bin\index.pl line 37.
    The first error is coming from the server, the second error is coming from perl. The bareword error that causes perl to emit its error message is not necessarily the cause of the http headers error, and it is only referenced because the server seems to think it may have been a failed attempt to print a header.

    Fixing the bareword error in your perl is not guaranteed to fix the problem with the headers. Remember that the first thing your script should print to STDOUT is an http header. If you're outputting HTML, this will usually work:

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