using diagnostics....

Discussion in 'Perl Misc' started by Dave, Oct 6, 2005.

  1. Dave

    Dave Guest

    Hi,

    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). 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.

    Thanks in advance,
    Dave
    Dave, Oct 6, 2005
    #1
    1. Advertising

  2. Dave

    Dave Guest

    I'm in the process of getting a short version of the program to
    generate the error... please don't bother with this post until I post
    that...
    Dave, Oct 6, 2005
    #2
    1. Advertising

  3. Dave

    Dave Guest

    Rrr... It won't replicate with a smaller program... but the same code
    (or at least I can't tell any difference, as I copied and pasted from
    the large program) gives that warning in the large program.

    Does that look like an improper way to do something, or does anyone
    have any idea what *could* be going on off the top of their heads?

    Thanks,
    Dave
    Dave, Oct 6, 2005
    #3
  4. Dave

    Dave Guest

    So it looks like it is working fine on the web when one of the
    variables I have between my 'X' things is defined, but it is undefined
    when run from the shell, so it gives that error.

    Sorry to muddy up the newsgroup with this.

    Dave
    Dave, Oct 6, 2005
    #4
  5. Dave

    Guest

    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
    , Oct 7, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Conorozzo
    Replies:
    5
    Views:
    11,322
    David Conorozzo
    Dec 15, 2003
  2. Heiko Besemann
    Replies:
    1
    Views:
    2,876
    Harsh Thakur
    Feb 19, 2004
  3. Jiho Han
    Replies:
    1
    Views:
    362
    Natty Gur
    May 20, 2004
  4. Ram
    Replies:
    2
    Views:
    6,110
  5. stand__sure
    Replies:
    2
    Views:
    1,116
    stand__sure
    Aug 29, 2005
Loading...

Share This Page