Hi All
I seem to have a problem with scope and/or handling objects here.
If I use 'my worksheet = $workbook->add_worksheet("$branchNumber") or die "Couldn't add worksheet $branchNumber \n" ;'
then I get 'use of uninitialized variable' when I try to add to the worksheet outside the innermost if {} block.
(which makes sense to me - my restricts it to that block)
If I initialize the $worksheet variable in the outer loop [as below] to make it 'more global'
it creates the worksheets and runs without warning or error, but doesn't put any contents into the worksheets.
What's going on here?
Comments appreciated
Brian


foreach my $fileToProcess (@filesToProcess) {
my $workbookName = basename("$fileToProcess",'.txt') ;
my $workbook = Spreadsheet::WriteExcel -> new("$workbookName.xls") or die "Error Creating $workbookName : $!" ;
my @format = (' ', ' ') ;
my $branchNumber = 0 ;
my $previousBranchNumber = 0 ;
my $row = 1 ;
my $worksheet ;
open (RAWREPORT, "$fileToProcess") or die "Can't open $fileToProcess because $!" ;


while (<RAWREPORT>) {
my @linesToDiscard = ( q(\f), q(^DATE : ), q(^\s{15,}PART ), q(^COUNTER QTY), q(^\s+$) ) ;
my $lineItem = $_ ;
next if grep { $lineItem =~ /$_/ } @linesToDiscard ;
if (/^BRANCH : (\d{1,2})/) {
$previousBranchNumber = $branchNumber ;
$branchNumber = $1 ;
if ($previousBranchNumber ne $branchNumber) {
my @worksheetHeadings = ('Qty.', 'Part Number', 'Description', 'Invoice Date', 'Customer #', 'Customer', 'Invoice #', 'ID');
my $headingFormat = ' ' ; #FIXME - need to define these formats
$worksheet = $workbook->add_worksheet("$branchNumber") or die "Couldn't add worksheet $branchNumber \n" ;
$worksheet->write(0, [EMAIL PROTECTED], $headingFormat) ;
}
}
my @linesToKeep = unpack ("A15 A19 A35 A8 A11 A30 A7 A4" , $_) ;
$worksheet->write($row, [EMAIL PROTECTED]) ;
$row ++ ;
}
$workbook->close() ;
}



-- Photo gallery at http://www.bmckee.ca/gallery


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to