Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Use of Uninitialized Value at numeric

Posted on 2006-03-29
Medium Priority
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 Script.pl line 85” and “Can't modify non-lvalue subroutine call at J:\Documents\New Scheduling Script.pl 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

Adam314 earned 1000 total points
ID: 16323332
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.

Assisted Solution

wlfs earned 1000 total points
ID: 16377150
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)

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Six Sigma Control Plans
Suggested Courses

580 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