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

This is a small program used to list the alert_logs of various databases listed in a text file (oratab). When I run the program the while loop picks up all the database names from the oratab but when the %dbLogLst hash is called in a subsequent foreach loop it randomly encounters variable initialization errors. The errors are random but consistent in that they databases giving errors are always the same. I'm hoping this is something obvious... I'm new to Perl so any help is greatly appreciated.

----------------------------------------------------------- #!/usr/bin/perl # use warnings; use strict; # my ($db,$line,$home,$boot,$bkup,$dbName,@dbList,%dbHomeLst,%db +BkupLst,%dbBootLst,%dbLogLst); my $oratab = $ENV{'ORATAB'}; # open OT, "$ENV{'ORATAB'}" + or die "Oratab not accessible ($!)"; while (defined ($line = <OT>)) { next if $line =~ /^#/; next if $line =~ /^\s*$/; chomp $line; ($dbName, $home, $boot, $bkup) = split ":", $line; push (@dbList,$dbName); print "DBNAME = $dbName\n"; $dbHomeLst{$dbName} = $home; $dbBkupLst{$dbName} = $bkup; $dbBootLst{$dbName} = $boot; $dbLogLst{$dbName} = < $ENV{'DIAG'}/$dbName/log/alert_ +$dbName.log >; } close OT; # # My Tests # foreach $db (@dbList) { print "Name = $db\n"; print "Home = $dbHomeLst{$db}\n"; print "Bkup = $dbBkupLst{$db}\n"; print "Boot = $dbBootLst{$db}\n"; print "DbLog = $dbLogLst{$db}\n"; } -------------------------------------------------------------

The output:

DBNAME = bea DBNAME = busopp DBNAME = cdms DBNAME = cip Name = bea Home = /orasys00/app/oracle/product/9.2.0 Bkup = Y Boot = Y DbLog = /orasys00/app/dpc/bea/log/alert_bea.log Name = busopp Home = /orasys00/app/oracle/product/9.2.0 Bkup = Y Boot = Y Use of uninitialized value in concatenation (.) or string at listDbs.p +l line 31. DbLog = Name = cdms Home = /orasys00/app/oracle/product/9.2.0 Bkup = Y Boot = Y DbLog = /orasys00/app/dpc/cdms/log/alert_cdms.log Name = cip Home = /orasys00/app/oracle/product/9.2.0 Bkup = Y Boot = Y Use of uninitialized value in concatenation (.) or string at listDbs.p +l line 31. DbLog =

Here is the sample OraTab file:

bea:/orasys00/app/oracle/product/9.2.0:Y:Y busopp:/orasys00/app/oracle/product/9.2.0:Y:Y cdms:/orasys00/app/oracle/product/9.2.0:Y:Y cip:/orasys00/app/oracle/product/9.2.0:Y:Y

Replies are listed 'Best First'.
Re: Random Unitialized Value Errors
by ikegami (Patriarch) on Aug 26, 2009 at 22:49 UTC

    You're calling glob in scalar context (via <...>). glob acts as an iterator, returning undef once all the results have been returned. For example,

    $ perl -wle'print scalar <{a,b,c}> for 1..6' a b c Use of uninitialized value in print at -e line 1. a b

    Or something closer to what you have,

    $ perl -wle'print scalar < $_ > for 1..6' 1 Use of uninitialized value in print at -e line 1. 3 Use of uninitialized value in print at -e line 1. 5 Use of uninitialized value in print at -e line 1.

    What are you trying to do with <...>? I think you might simply want

    $dbLogLst{$dbName} = "$ENV{'DIAG'}/$dbName/log/alert_$dbName.log";
      That was it, ikegami! The typeglob was not needed and replacing the <> with "" worked. Thanks so much.
        Typeglobs (which are also known as globs) are symbol table entries. They are completely unrelated to glob, the operator you were using.
Re: Random Unitialized Value Errors
by bichonfrise74 (Vicar) on Aug 26, 2009 at 22:42 UTC
    I think it is because there is no value for
    DbLog =
    specifically coming from busopp:/orasys00/app/oracle/product/9.2.0:Y:Y

    Are you sure there is a file when you run this for busopp?
    $dbLogLst{$dbName} = < $ENV{'DIAG'}/$dbName/log/alert_$dbName.log >;