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

Monks,

I am sure this should not be complicated:

#!/usr/bin/perl use strict; use warnings; use diagnostics; use Getopt::Std; use DBI; use DateTime; use FileHandle; use Socket; use lib q(/home/dds/utils); use DDSUtils; # a few 'my $thisNthat;'s ... print "$0: ",(scalar localtime), "\n"; # do stuff... print "$0: " ,(scalar localtime), " run complete\n"; $Odbh->disconnect; exit;

Compiles OK, but when it runs:

qg@dev:~/svnwork/dds/trunk/src$ ./alerts.pl ./alerts.pl: Tue Oct 21 11:32:20 2008 ./alerts.pl: Tue Oct 21 11:32:21 2008 run complete Use of uninitialized value in require at /usr/share/perl/5.8/AutoLoade +r.pm line 92 during global destruction (#1) (W uninitialized) An undefined value was used as if it were alread +y defined. It was interpreted as a "" or a 0, but maybe it was a mi +stake. To suppress this warning assign a defined value to your variables. To help you figure out what was undefined, perl tells you what ope +ration you used the undefined value in. Note, however, that perl optimiz +es your program and the operation displayed in the warning may not necessa +rily appear literally in your program. For example, "that $foo" is usually optimized into "that " . $foo, and the warning will refer +to the concatenation (.) operator, even though there is no . in your program.

It now gets interesting ... As I was composing this node I thought "these monks don't want to see the long diagnostic explanation of the warning - I'll comment out the 'use diagnostics;' and just get the brief warning"...

qg@dev:~/svnwork/dds/trunk/src$ !! ./alerts.pl ./alerts.pl: Tue Oct 21 11:32:53 2008 ./alerts.pl: Tue Oct 21 11:32:54 2008 run complete qg@dev:~/svnwork/dds/trunk/src$

The only difference between the two runs is that I commented out the

use diagnostics;
line. But it seems to have made the warning go away.

¿Qué pasa?


This signature will be ready by Christmas

Replies are listed 'Best First'.
Re: Use of uninitialized value in require at ...AutoLoader.pm ?
by Narveson (Chaplain) on Oct 21, 2008 at 15:21 UTC

    You may ignore this diagnostic message with my blessing.

    The consensus is that you'll always want to develop under strict and warnings, but wait to use diagnostics until you find yourself needing the extra help.

    If you have the time and motivation to understand why you got this diagnostic message, you'll want to try variations in which you omit some of the modules you are currently using, and track the errors, warnings, and diagnostics that result from each omission.

Re: Use of uninitialized value in require at ...AutoLoader.pm ?
by JadeNB (Chaplain) on Oct 21, 2008 at 19:34 UTC
    Despite Narveson's blessing, I, too, am curious about why you should get, not just a terse warning, but no warning at all under warnings—since a quick perusal of the diagnostics documentation suggests to me that it's meant only to amplify, not to add to, warnings's protestations. Unfortunately, I only have AutoLoader v.5.63—the one that comes with Perl 5.10.0—which doesn't have a require on line 92; and Perl 5.8.8's v.5.60 doesn't seem to be available on CPAN.

    I searched the v.5.63 code for requires, and it does only two kinds of requires—one from a filename provided by find_filename, which seems explicitly to prevent itself from returning undef; and one require $path, which is executed only if (defined($path)). Could you post what's happening on line 92 of your AutoLoader.pm?

Re: Use of uninitialized value in require at ...AutoLoader.pm ?
by ikegami (Patriarch) on Oct 21, 2008 at 19:40 UTC

    I cannot reproduce the problem. Could it be related to DDSUtils? (I had to comment out that line.)

    At the very least, tell us which version of Autoloader you have so we can identify the line where the warning originates.

      Thank you both.

      I can't get the answers till later - will get back a.s.a.p.

      This signature will be ready by Christmas
      This is indeed version 5.60 of Autoloader, running under perl 5.8.8.

      The first few lines are:

      package AutoLoader; use strict; use 5.006_001; our($VERSION, $AUTOLOAD); my $is_dosish; my $is_epoc; my $is_vms; my $is_macos; BEGIN { $is_dosish = $^O eq 'dos' || $^O eq 'os2' || $^O eq 'MSWin32' || $ +^O eq 'NetWare'; $is_epoc = $^O eq 'epoc'; $is_vms = $^O eq 'VMS'; $is_macos = $^O eq 'MacOS'; $VERSION = '5.60'; } AUTOLOAD { my $sub = $AUTOLOAD;

      This is the same code as that cited by Anonymous Monk in http://search.cpan.org/~nwclark/perl-5.8.8/lib/AutoLoader.pm.

      Lines 91-2 say:

      local $!; # Do not munge the value. eval { local $SIG{__DIE__}; require $filename };
      where the previous block (most of the AUTOLOAD sub, in fact) goes to great lengths to establish $filename.

      ikegami, I don't believe DDSutils is involved. That just exports a couple of subs and some quasi-constants.No clever BEGIN/END stuff.

      I observed that the Autoloader module does not itself use warnings; - I am reminded of another situation in the past where a CPAN module (I don't recall which) peppered my web server error log with warnings when my code ran under #!/usr/bin/perl -w because my invocation was imposing warningfulness on it. . That went away when I replaced #!/usr/bin/perl -w with use warnings; which kept my warnable condition to my own scope. I am just wondering whether something similar could be happening with regard to diagnostics but it seems rather far fetched.

      Update: Forgot to say:

      This is perl, v5.8.8 built for i486-linux-gnu-thread-multi ; out-of-the-box Ubuntu 8.04 LTS.


      This signature will be ready by Christmas

        I hope it is not considered poor etiquette to follow up on my own message - if so, please excuse this.

        Just seen on perldoc's diagnostics (emphases are in the original):

        (Note that this does enable perl's -w flag.)

        So the throwaway comment on scoping turns out to be relevant after all. Once more the Universe says 'RTFM'.

        I suspect that is probably about it...? Nothing further, your honour.


        This signature will be ready by Christmas

        diagnostics is causing the warning to appear, but it's not the cause of the warning. It appears that Autloader is doing require undef;. I'd wonder why.