Re: using diagnostics....



Dave wrote:
>
> I am using strict and warnings. I have also unsucessfully looked online
> in google and perldocs on how to localize a filehandle (though I'm not
> sure that is what I need to be doing).

perldoc -q local

(scroll down until you see:
How can I make a filehandle local to a subroutine?
How do I pass filehandles between subroutines?
How do I make an array of filehandles?

> I get the following error when I
> turn on diagnostics. :
>
> Use of uninitialized value in concatenation (.) or string at
> /usr/lib/perl5/site_perl/5.8.0/UUMembers.pm line 362 (#1)
> (W uninitialized) An undefined value was used as if it were already
> defined. It was interpreted as a "" or a 0, but maybe it was a
> mistake.
> To suppress this warning assign a defined value to your variables.
>
>
> The corresponding code id:
>
> 361: print "Content-type: text/html\n\n";
> 362: print<<X;
> 363: <head>
> 364: X
>
> What do I need to do in order to code this correctly? What is the
> error? How do I define X to something?
>
> I will have more html in between line 362 and 364, otherwise I would
> have simply used a print command.
>

If a variable, say $foo is declared but is never initialized
and then embedded in your here-doc, Perl will emit the warning
you've just seen. If you get this warning and there are several
embedded variables in a here-doc or if-else structure, Perl can't
drill down closely enough to tell you which one is undefined.

Often just inspecting the code closely and debugging on the
command line will provide clues. By the way, the CGI module or
equivalent is also easier and preferable to hand rolling HTML.
You could even arrange to display warnings to the screen which
may make them easier to spot:

use CGI qw/:standard warningsToBrowser/;
warningsToBrowser(1);
print header, start_html;

print <<X;
...$foo ....
...... $bar
X
# print "embedded variable \$foo is $foo"; # var. defined test
# print "embedded variable \$bar is $bar";

print end_html;
__END__


hth,
--
Charles DeRykus

.



Relevant Pages

  • Re: Determine read/write status of filehandles connected to memory objects.
    ... Any script containing that subroutine that was run on pre-5.6 perl would, ... A more specific test if the warning was indeed the text "Filehandle ... "Reply" at the bottom of the article headers. ...
    (comp.lang.perl.misc)
  • Re: Determine read/write status of filehandles connected to memory objects.
    ... string to the filehandle and catch the warning if it fails: ... Any script containing that subroutine that was run on pre-5.6 perl would, ...
    (comp.lang.perl.misc)
  • Read from filehandle opened for appending
    ... If I try to read from a filehandle opened for appending, I get no warning ... Are these oversights, or are there sound reasons for these behaviours? ...
    (comp.lang.perl.misc)
  • Re: Which is better?
    ... filehandle reference, that variable becomes subject to 'use strict;'. ... Perl will simply emit a warning telling you've printed to a closed ... print $OUTFILE "This is some text\n"; ... Perl will cease executing the code, ...
    (perl.beginners)
  • Re: use strict and filehandles
    ... I had a similar problem passing a filehandle to a sub and learned that I had to use the typeglob instead. ... In this case a bare word does everything I need it ... >What is this warning trying to prevent? ... A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools. ...
    (perl.beginners)