Use of Uninitialized Value at numeric

Posted on 2006-03-29
Last Modified: 2010-08-05
I was hoping that someone could take a minute and look at the quasi – finished script below and give me some pointers on a couple of things. Currently, the directory search for the files works, but it also returns “.” and “..” to the array which really messing things up for the rest of the script b/c “.” and “..” are obviously not filenames that data can't be pulled from. I’ve had to comment out this section and hard code the $filename variable for now to get it to run. The critical errors are when the script starts the conditional testing loop and the message I get is: “Use of uninitialized value in numeric gt (>) at J:\Documents\New Scheduling line 85” and “Can't modify non-lvalue subroutine call at J:\Documents\New Scheduling line 117.” I have tried replacing the conditional operater e.g.” >” with neq, but I still get the same error. Again if someone could take a look at these areas and let me know when or how I went wrong I would be very appreciative.

#!/usr/bin/perl -w

use strict;

use Win32::OLE qw(in with);

use Win32::OLE::Const 'Microsoft Excel';

use Win32::OLE::Variant;

use Win32::OLE::NLS qw(:LOCALE :DATE);

use Win32::OLE::NLS qw(:LOCALE :TIME);

use Win32::File;

use Data::Dumper;

$Win32::OLE::Warn = 3;

use utf8;



#my $rowNumber = 1;

my $filename = "C:\\Test\\Test_Cases2";

#my @listofFiles;


#chdir ('C:\Test');

#opendir(Dir, ".") or die;

#while ($filename = readdir Dir){

#    next if $filename =~m/^DNE/i;

#    push @listofFiles, $filename;


#closedir Dir;


our (%output, %tmphash, $reference, $currentOutputRow, $OutputSheet);


#foreach my $filename (@listofFiles){

#    print Dumper @listofFiles;


my $Excel = Win32::OLE->GetActiveObject('Excel.Application')||

            Win32::OLE->new('Excel.Application', 'Quit');

my $book = $Excel->workbooks->open($filename);

my $sheet = $book->worksheets("Weekly_Snapshot");


for my $rowNumber (1..99999){


    #Read the current Row of data from the spreadhsheet.


    my $ID = $sheet->Range("A".$rowNumber)->{'Value'};

    my $ED = $sheet->Range("B".$rowNumber)->{'Value'};

    my $PL = $sheet->Range("C".$rowNumber)->{'Value'};

    my $RG = $sheet->Range("D".$rowNumber)->{'Value'};

    my $CT = $sheet->Range("E".$rowNumber)->{'Value'};

    my $IL = $sheet->Range("F".$rowNumber)->{'Value'};

    my $IS = $sheet->Range("G".$rowNumber)->{'Value'};

    my $CS = $sheet->Range("H".$rowNumber)->{'Value'};

    my $RDF = $sheet->Range("I".$rowNumber)->{'Value'};

    my $RDT = $sheet->Range("J".$rowNumber)->{'Value'};

    my $CM = $sheet->Range("K".$rowNumber)->{'Value'};

    my $SO = $sheet->Range("L".$rowNumber)->{'Value'};

    my $LI = $sheet->Range("M".$rowNumber)->{'Value'};

    my $AC = $sheet->Range("N".$rowNumber)->{'Value'};

    my $CD = $sheet->Range("O".$rowNumber)->{'Value'};

    my $NW = $sheet->Range("P".$rowNumber)->{'Value'};

    my $SL = $sheet->Range("Q".$rowNumber)->{'Value'};

    my $WH = $sheet->Range("R".$rowNumber)->{'Value'};

    my $QT = $sheet->Range("S".$rowNumber)->{'Value'};

    my $SQT = $sheet->Range("T".$rowNumber)->{'Value'};

    my $OP = $sheet->Range("U".$rowNumber)->{'Value'};

    my $CR = $sheet->Range("V".$rowNumber)->{'Value'};

    my $REQS = $sheet->Range("W".$rowNumber)->{'Value'};

    my $CRB = $sheet->Range("X".$rowNumber)->{'Value'};

    my $REQ = $sheet->Range("Y".$rowNumber)->{'Value'};

    my $MOD = $sheet->Range("Z".$rowNumber)->{'Value'};

    my $MODB = $sheet->Range("AA".$rowNumber)->{'Value'};

    my $TMAD = $sheet->Range("AB".$rowNumber)->{'Value'};

    my $CRD = $sheet->Range("AC".$rowNumber)->{'Value'};

    my $RSUB = $sheet->Range("AD".$rowNumber)->{'Value'};

    my $SCH = $sheet->Range("AE".$rowNumber)->{'Value'};


    my $compoundkey = "$ID-$SO-$LI";

    print Dumper $compoundkey;

    last if $compoundkey eq '--';


    #Condtional Testing


    if ($MOD > $output{$compoundkey}->{MOD}){                                                                          <<<<<critcal error

    delete ($output{$compoundkey});


#    if ($MOD > $output{$compoundkey}->{$MOD} && $output{$compoundkey}->{$ID}!= {$ID}){

#    delete ($output{$compoundkey});

#    if ($MOD > $output{$compoundkey}->{$MOD} && $output{$compoundkey}->{$ID}!= {$ID}){

#    delete ($output{$compoundkey});

#    if ($MOD > $output{$compoundkey}->{$MOD} && $output{$compoundkey}->{$ID}!= {$ID}

#    && $output{$compoundkey}->{$ED, $PL, $RG, $CT, $IL, $IS, $CS, $RDF, $RDT, $CM, $AC,

#                                $CD, $NW, $SL, $WH, $SQT, $OP, $REQS, $CRB, $REQ, $MODB,

#                                $TMAD->Date(DATE_SHORTDATE), $CRD->Date(DATE_SHORTDATE),

#                                $RSUB, $SCH}!= {$ED, $PL, $RG, $CT, $IL, $IS, $CS, $RDF, $RDT, $CM, $AC,

#                                $CD, $SL, $WH, $SQT, $OP, $REQS, $CRB, $REQ, $MODB,

#                                $TMAD->Date(DATE_SHORTDATE), $CRD->Date(DATE_SHORTDATE), $RSUB, $SCH}){

#                                delete ($output{$compoundkey});


    next if $output{$compoundkey};


    $output{$compoundkey} = {ID => $ID, SO => $SO, LI => $LI, QT => $QT,

                            CR => $CR, MOD => $MOD, ED => $ED, PL => $PL,

                            RG => $RG, CT => $CT, IL => $IL, IS => $IS,

                            CS => $CS, RDF => $RDF, RDT =>$RDT, CM => $CM,

                            AC => $AC, CD => $CD, NW => $NW, SL => $SL,

                            WH => $WH, SQT => $SQT, OP => $OP, REQS => $REQS,

                            CRB => $CRB, REQ => $REQ, MODB => $MODB, TMAD => $TMAD,

                            CRD => $CRD, RSUB => $RSUB, SCH => $SCH};


    my $outputSheet = $book->worksheets('Keepers');                                                        <<<<<2nd critical error

    my $currentOutputRow =1;

    my $numofOutputRows = keys(%output);


    for my $compoundkeys (keys(%output)){

            $outputSheet->Row("A$currentOutputRow") = $output{$compoundkey}->{$ID};

            $outputSheet->Row("B$currentOutputRow") = $output{$compoundkey}->{$SO};

            $outputSheet->Row("C$currentOutputRow") = $output{$compoundkey}->{$LI};

            $outputSheet->Row("D$currentOutputRow") = $output{$compoundkey}->{$QT};

            $outputSheet->Row("E$currentOutputRow") = $output{$compoundkey}->{$CR};

            $outputSheet->Row("F$currentOutputRow") = $output{$compoundkey}->{$MOD};

            $outputSheet->Row("G$currentOutputRow") = $output{$compoundkey}->{$ED};

            $outputSheet->Row("H$currentOutputRow") = $output{$compoundkey}->{$PL};

            $outputSheet->Row("I$currentOutputRow") = $output{$compoundkey}->{$RG};

            $outputSheet->Row("J$currentOutputRow") = $output{$compoundkey}->{$CT};

            $outputSheet->Row("K$currentOutputRow") = $output{$compoundkey}->{$IL};

            $outputSheet->Row("L$currentOutputRow") = $output{$compoundkey}->{$IS};

            $outputSheet->Row("M$currentOutputRow") = $output{$compoundkey}->{$CS};

            $outputSheet->Row("N$currentOutputRow") = $output{$compoundkey}->{$RDF};

            $outputSheet->Row("O$currentOutputRow") = $output{$compoundkey}->{$RDT};

            $outputSheet->Row("P$currentOutputRow") = $output{$compoundkey}->{$CM};

            $outputSheet->Row("Q$currentOutputRow") = $output{$compoundkey}->{$AC};

            $outputSheet->Row("R$currentOutputRow") = $output{$compoundkey}->{$CD};

            $outputSheet->Row("S$currentOutputRow") = $output{$compoundkey}->{$NW};

            $outputSheet->Row("T$currentOutputRow") = $output{$compoundkey}->{$SL};

            $outputSheet->Row("U$currentOutputRow") = $output{$compoundkey}->{$WH};

            $outputSheet->Row("V$currentOutputRow") = $output{$compoundkey}->{$SQT};

            $outputSheet->Row("W$currentOutputRow") = $output{$compoundkey}->{$OP};

            $outputSheet->Row("X$currentOutputRow") = $output{$compoundkey}->{$REQS};

            $outputSheet->Row("Y$currentOutputRow") = $output{$compoundkey}->{$CRB};

            $outputSheet->Row("Z$currentOutputRow") = $output{$compoundkey}->{$REQ};

            $outputSheet->Row("AA$currentOutputRow") = $output{$compoundkey}->{$MODB};

            $outputSheet->Row("AB$currentOutputRow") = $output{$compoundkey}->{$TMAD};

            $outputSheet->Row("AC$currentOutputRow") = $output{$compoundkey}->{$CRD};

            $outputSheet->Row("AD$currentOutputRow") = $output{$compoundkey}->{$RSUB};

            $outputSheet->Row("AE$currentOutputRow") = $output{$compoundkey}->{$SCH};




Question by:KFFrench
    LVL 39

    Accepted Solution

    The first error on this line:
    if ($MOD > $output{$compoundkey}->{MOD}){

    The first time through the loop, $output doesn't have a value.  This is why you get the error.
    It gets set several lines after this line, so on subsequent loops, it will contain whatever it was set to in the previous iteration of the loop.

    The other error could be because you first declare outputSheet with our at the top, then try to redeclare it with my on the line that has the error.
    LVL 5

    Assisted Solution

    Concerning the problem with "." and "..". Actually you don't want any directories at all, do you? So, you should only iterate over real files (or symbolic links) but no directories like so:

    while ($filename = grep !-d, readdir DIR)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Suggested Solutions

    Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
    Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now