Use of uninitialized value in print


P

Pam

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 = '(e-mail address removed)';


# 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
 
Ad

Advertisements

M

Mumia W.

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.
 
Ad

Advertisements

B

Brian McCauley

Mumia said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top