Use of uninitialized value in print

Discussion in 'Perl Misc' started by Pam, Sep 18, 2006.

  1. Pam

    Pam Guest

    Hello
    I ran into a problem that I have been working on, the warning use of
    unitialized value at print
    I have tried everything I know. I have initialized my variables but I
    don't get the contents of the value. I have looked at perldoc but
    can't seem to resolve the issue of not getting my
    value contents. It compiles through to the end. I'm just begining to
    get more extensive into Perl. Trying to meet a dealine. I had to take
    a step back and look at my logic since this is my first stab at
    Win32::OLE. I need another pair oif eyes because I am not seeing the
    obvious

    use Spreadsheet::parseExcel;
    use Spreadsheet::WriteExcel;
    use Win32::OLE qw(in with);
    use Win32::OLE::Const 'Microsoft Excel';
    use warnings;

    $filename ="CCB.txt";


    open(FILE,">$filename") || die("Cannot Open File $filename : $!" );
    print FILE $query_result->content;
    print "File open ";


    close (FILE);


    #This is the holding variable for date because the requirements want
    the date in filename


    $datestamp = strftime("%Y%m%d",localtime) ;


    # Open the Comma Separated Variable file
    open (CSVFILE, $filename) or die "$filename: $!";


    # Create a new Excel workbook
    my $workbook =
    Spreadsheet::WriteExcel->new("3GSoftwareCCB_MeetingAgenda$datestamp.xls");

    my $worksheet = $workbook->add_worksheet();


    # get already active Excel application or open new
    my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
    || Win32::OLE->new('Excel.Application', 'Quit');


    # Create a new CSV parsing object
    my $csv = Text::CSV_XS->new;


    # Row and column are zero indexed
    my $row = 0;


    while (<CSVFILE>) {
    if ($csv->parse($_)) {
    my @Fld = $csv->fields;


    my $col = 0;
    foreach my $token (@Fld) {
    $worksheet->write($row, $col, $token);
    $col++;
    }
    $row++;
    if ($row > 1){
    $count = $count + 1;


    $total = $count;


    }


    }
    else {
    my $err = $csv->error_input;
    print "Text::CSV_XS parse() failed on argument: ", $err, "\n";
    }



    }


    print "Adding sheet1\n";

    print "Now will format .xls file\n";


    #Holding Variables for mailing list
    $Name1 = '';


    # Add a Format
    $format = $workbook->add_format();
    #must set wrap for CCB comments and Description
    $format->set_text_wrap();
    $format->set_bold();
    $format->set_bg_color('51');
    $format->set_border();
    $format->set_bottom();
    $format->set_top();
    $format->set_left();
    $format->set_right();


    # The general syntax is write($row, $col, $token, $format)


    # Write some formatted text


    $col = 0;
    $row = 0;


    $worksheet->write(0, $col, "Identifier", $format,);
    $worksheet->write(0, 1, "Team Comments", $format,);
    $worksheet->write(0, 2, "Description", $format);
    $worksheet->write(0, 3, "Status", $format);
    $worksheet->write(0, 4, "Severity", $format);
    $worksheet->write(0, 5, "Priority", $format);
    $worksheet->write(0, 6, "CCBComments_encl", $format);
    $worksheet->write(0, 7, "Primary-feature-team", $format);
    $worksheet->write(0, 8, "Sub-feature-team", $format);
    $worksheet->write(0, 9, "Project", $format);
    $worksheet->write(0, 10,"Product", $format);
    $worksheet->write(0, 11,"Products-targeted", $format);
    $worksheet->write(0, 12,"Products-targed_del", $format);
    $worksheet->write(0, 13,"Products-targetd_add", $format);
    $worksheet->write(0, 14,"Program", $format);


    my $Book = $Excel->Workbooks->Open("D:/Profiles/w8143c/My


    Documents/Spreadsheet-WriteExcel-2.17/3GSoftwareCCB_MeetingAgenda$datestampĀ­.xls");



    #$row = 1;
    $col = 11;


    print "Is this book geeting seen", $Book, "\n";


    #Tring to check for empty cell
    #This looks at Sheet1 in the workbook
    my $Sheet = $Book->Worksheets(1);


    for(my $row =1 ;
    $row <= $total ; $row++) {


    printf "At ($row, $col) the value is %s and the formula is %s\n",
    $Sheet->Cells($row,$col)->{'Value'},
    $Sheet->Cells($row,$col)->{'Formula'};


    print $row, "\n";


    }


    After this I get warning talking about use of uninitialized value and

    it does not print value(which I was hoping to get contents of the cell
    but print statement is empty


    print $total, "\n";


    while ($row <= $total)
    {
    $worksheet->write($row, $col, "3G_Platform", $format2);


    $row= $row + 1;



    }


    #Here I am writing to the file but I need to check if the row is empty

    If I use something like if ($Sheet->Cells($row,$col)->{'Value'} " ")
    it blows up on me. If I put a string in it complains about it is not
    numeric

    Need your help, I am spinning my wheels here

    Thanks,
    Pamela
    Pam, Sep 18, 2006
    #1
    1. Advertising

  2. Pam

    Mumia W. Guest

    On 09/18/2006 01:42 PM, Pam wrote:
    > Hello
    > I ran into a problem that I have been working on, the warning use of
    > unitialized value at print
    > [...]
    > # Row and column are zero indexed
    > my $row = 0;
    >
    >
    > while (<CSVFILE>) {
    > if ($csv->parse($_)) {
    > my @Fld = $csv->fields;
    >
    >
    > my $col = 0;
    > foreach my $token (@Fld) {
    > $worksheet->write($row, $col, $token);
    > $col++;
    > }
    > $row++;
    > if ($row > 1){
    > $count = $count + 1;
    >
    >
    > $total = $count;
    >
    >
    > }
    > [...]


    If $row is never greater than one, $total will never be assigned, so I
    suspect that $row never got to be greater than one. Either that or
    $csv->parse($_) failed (returned a false value).

    Down below, $total is undefined when you print it because it was never
    assigned up above.
    Mumia W., Sep 19, 2006
    #2
    1. Advertising

  3. Mumia W. wrote:

    > Down below, $total is undefined when you print it because it was never
    > assigned up above.


    Further evidence to support this comes from the fact that the stament
    immediately before the assignment to $total would also emit a warning
    and the user never mentioned this.
    Brian McCauley, Sep 19, 2006
    #3
    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. G Kannan
    Replies:
    1
    Views:
    1,233
    Eric J. Roode
    Oct 11, 2003
  2. Sukhbir Dhillon
    Replies:
    1
    Views:
    6,251
    Joe Smith
    Apr 5, 2004
  3. smartins68
    Replies:
    1
    Views:
    6,001
    Joe Smith
    Jun 9, 2004
  4. Jon Anderson

    Newbie. Use of uninitialized value in print??

    Jon Anderson, Apr 3, 2005, in forum: Perl Misc
    Replies:
    7
    Views:
    232
  5. Replies:
    4
    Views:
    156
    Tad McClellan
    Nov 2, 2006
Loading...

Share This Page