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

Quick question, if I may:

CGI script. Perl 5.6.x

I get errors such as Use of uninitialized value in concatenation (.) or string at /blah/mycode.pm line 488. When I look at the line it has maybe 5 variables listed on it. Is there a way to get it to tell me which are not initialised?

I'd rather make the minimum changes - I just want to know the names of the symbols...

Thanks... M.


Thanks for the answers: Just to clarify - anytime that error occurs, no matter where, I want to know the variable name. Sure I can do prints, etc, around a particular instance but I'd rather change the error reporting system.
  • Comment on CGI... uninitialized value... which variables?

Replies are listed 'Best First'.
Re: CGI... uninitialized value... which variables?
by Roger (Parson) on Sep 29, 2004 at 11:59 UTC
    You could use the Data::Dumper module.

    use Data::Dumper; ... my ($a, $b, $c, $d); $a = 1; $b = 2; $d = 4; print Dumper([ $a, $b, $c, $d ]);

    And check for variable with 'undef' value...

      Thanks... see above - am looking for a generic solution
Re: CGI... uninitialized value... which variables?
by amt (Monk) on Sep 29, 2004 at 13:05 UTC
    If you are looking to debug, you can add this block:
    print '$var1' unless($var1); print '$var2' unless($var2);


    amt.

    perlcheat
      Thanks... see above - am looking for a generic solution...
Re: CGI... uninitialized value... which variables?
by kutsu (Priest) on Sep 29, 2004 at 16:49 UTC

    For the varies errors and warnings I get from CGI, I like to have a semi-generic module I can call to print to a logfile with the basic information (variable data, short descriptive error message, time/date, line number, some error code/variable to send to HTML::Template (for the user to see), and etc. Note this will not replace Data::Dumper for debugging errors nor die for serious errors, but is very helpful for errors like a param being empty or invalid (esp. if it is in a sub that you can call like this: error() unless defined $someparam;). Just my way of doing things.

    "Cogito cogito ergo cogito sum - I think that I think, therefore I think that I am." Ambrose Bierce

      Thanks.

      Do you have a mechanism to make it get called during die? That would be a great way of getting CGI to spit out the context information needed to make sense of why trouble had occurred.

      Is the code available anywhere?