Re: using diagnostics....
- From: "ced@xxxxxxxxxxxxxxxxxxxxx" <ced@xxxxxxxxxxxxxxxxxxxxx>
- Date: 7 Oct 2005 01:37:47 -0700
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
.
- References:
- using diagnostics....
- From: Dave
- using diagnostics....
- Prev by Date: Problem with perl & google
- Next by Date: Re: Is there a Perl Module The Does GCC like precompile on C++ files ?
- Previous by thread: Re: using diagnostics....
- Next by thread: variable question
- Index(es):
Relevant Pages
|