Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Use of uninitialized value in print

Reply
Thread Tools

Use of uninitialized value in print

 
 
Pam
Guest
Posts: n/a
 
      09-18-2006
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:arseExcel;
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 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

 
Reply With Quote
 
 
 
 
Mumia W.
Guest
Posts: n/a
 
      09-18-2006
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.

 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      09-19-2006
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use of uninitialized variable with print << HTMLEND (and $ENV) kevinwhite@bellsouth.net Perl Misc 4 11-02-2006 03:18 PM
Newbie. Use of uninitialized value in print?? Jon Anderson Perl Misc 7 04-03-2005 10:23 PM
Use of uninitialized value in concatenation smartins68 Perl 1 06-09-2004 05:46 AM
Re: Use of uninitialized value in concatenation (.) or string Error Sukhbir Dhillon Perl 1 04-05-2004 02:31 AM
Use of uninitialized value in concatenation (.) at register.pl line 38, <STDIN> line 10. G Kannan Perl 1 10-11-2003 11:58 AM



Advertisments