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

Hi,
My httpd error log file is giving me an error of
Use of uninitialized value in concatenation (.) at /Library/WebServer/CGI-Executables/traxx.pl line 314.
My Code is:
sub happy(){ print << "THANKS"; Content-type: text/html
The line that is generating errors is the print <<"thanks" line. The subroutine is cut and paste from some others that don't generate that error. The sub is generating the html output for the user to see after the function generates. There is no concatenation in this line. Why would I get this error?
thanks!

Replies are listed 'Best First'.
Re: Concat Error, but I'm not concatenating??
by davido (Cardinal) on Apr 03, 2004 at 10:12 UTC
    You showed us an incomplete syntax. And given that you "cut and paste" your code, I wonder if you maybe failed to paste the entire syntax, just as you did in your example snippet here.

    print << "THANKS"; Content-type: text/html
    ...is the beginning, and one line of a HERE document. But HERE docs must have an end tag. In the case of your code, everything from print << "THANKS"; on until you see THANKS a few lines later is all quoted material. If you didn't close your HERE doc, it could be runnning into the next THANKS tag, possibly where you copied and pasted this HERE-doc from.

    Since your HERE doc is a double-quoted construct, variable interpolation occurs. And if your HERE doc is runaway, and subsequently closed with the closing token at some point later in the script, it's possible that variables which haven't yet been populated are being interpolated in your script.

    Be sure to close your HERE docs, and if it is closed in your code, reflect that in your example snippets.

    I should also mention that Perl's error reporting sees the entire multi-line HERE doc as all belonging to the line that contains the opening tag syntax. Hense, even if the problem is actually the fifth line of the HERE doc's text, the error will be reported as the line on which the opening tag is found. I hope this helps! Good luck.


    Dave

Re: Concat Error, but I'm not concatenating??
by Abigail-II (Bishop) on Apr 03, 2004 at 10:03 UTC
    Most likely you have an undefined variable in the here doc that is following the mentioned line.

    Abigail

      Found the problem, but still not sure how to make a solution out of it.
      I have a web interface for the perl script. html page with 9 input values making a get request.
      I also have a perl script that sends data directly to the perl script.
      The perl script only passes 3 of the values using lwp, causing the undefined error for the other 6 variables.

      So anytime I submit data through the webpage, I don't get any errors. When my other perl scripts post data to the collector script, they don't pass the other values. I guess I could have my external scripts post null data like:
      $val = ""; $val2 = "123"; $url = "http://localhost/get.pl?&val1=".$val."&val2=".$val2; giving http://localhost/get.pl?&val1=&val2=123
      I think that should make the values defined in my collector script?
      The rest of my other sub is included, but the above is certainly the problem. It's important that my script know whether the user intended to include data with his get, so I need to be able to differentiate the difference between 0 and null.
      Thanks!
      sub happy(){ print << "THANKS"; Content-type: text/html <HTML> <HEAD> <TITLE>Trackerhappy :-)</TITLE> </HEAD> <BODY> ID: $node<br> Lat: $lat<br> Lon: $lon<br> </BODY> </HTML> THANKS }
        $node, $lat or $lon are undefined. When you assign the values, add an || ''; - if it's ok for them to be empty. Eg
        $node = defined $q->param('node') ? $q->param('node') : '';
        cLive ;-)
Re: Concat Error, but I'm not concatenating??
by muba (Priest) on Apr 03, 2004 at 10:58 UTC
    Would you please show us the complete sub happy?