Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
It seems inefficient to me to write to an intermediate file then reopen this file and do some more processing on it before writing to the spreadsheet file. Can this be done in memory instead ? if so how ?# Open the output file for the cmdtxt audit trail selected open TXT,">$txt" or die "Can't create $txt : $!\n"; # execute the sql statement $sth=$dbh->prepare("@sql"); $sth->execute; while ($data = $sth->fetchrow_arrayref()) { chomp $data->[13]; $data->[13] =~ tr/\t//; # get rid of the tabs if ( $data->[4] > 1) { print TXT "$data->[13]"; } else { print TXT "\nBOR $data->[3]|$data->[2]|$data->[9]|$data->[10 +]|$data->[4]|$data->[13]"; } } $sth->finish; $dbh->disconnect; close TXT; # Create the spreadsheet and set up formats $workbook = Spreadsheet::WriteExcel->new("my.xls"); # Set up various workbook formats here.... # Create some worksheets $sheet1 = $workbook->add_worksheet('Tools'); $sheet2 = $workbook->add_worksheet('Client'); $sheet3 = $workbook->add_worksheet('Fares'); # create some column headings for each worksheet here... # Set up some lookup lists using Regexp::List here... # Read the intermediate file and populate the worksheets $/="BOR "; open TXT,"<$txt" or die "Can't open $txt : $!\n"; while( <TXT> ) { chomp; if( m[/\-] ) { $_ .= <TXT> until m[\-/]; s[ \s? / \- .+? \- / \s? ][]smgx;# cut out some unwanted txt chomp; } my @rec = split /\|/; $aa = $rec[0]; $bb = $rec[1]; $cc = $rec[2]; $dd = $rec[3]; # $rec[4] isn't used here $ee = $rec[5]; if ($ee =~ /$regexp1/) { popxls($sheet1,$normal,$darow); # populate worksheet 1 $darow++; } elsif ($ee =~ /$regexp2/) { popxls($sheet2,$normal,$arow); # populate worksheet 2 $arow++; } elsif ($ee =~ /$regexp3/) { popxls($sheet3,$normal,$srow); # populate worksheet3 $srow++; } } close TXT; sub popxls { $col = 0; my $type = $_[0]; my $fmt = $_[1]; my $row = $_[2]; $type->write($row, $col, "$ee", $fmt); $col++; $cmdtype->write($row, $col, $aa, $fmt); $col++; $cmdtype->write($row, $col, "$bb", $fmt); $col++; $cmdtype->write($row, $col, "$cc", $fmt); $col++; $cmdtype->write($row, $col, "$dd", $fmt); }
Thanks in advance
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Direct to spreadsheet
by McDarren (Abbot) on Jan 23, 2006 at 10:58 UTC | |
by Anonymous Monk on Jan 23, 2006 at 11:40 UTC | |
by McDarren (Abbot) on Jan 23, 2006 at 15:08 UTC | |
by Anonymous Monk on Jan 23, 2006 at 16:03 UTC | |
by McDarren (Abbot) on Jan 23, 2006 at 17:22 UTC | |
|
Re: Direct to spreadsheet
by GrandFather (Saint) on Jan 23, 2006 at 10:48 UTC | |
by Anonymous Monk on Jan 23, 2006 at 13:56 UTC | |
by GrandFather (Saint) on Jan 23, 2006 at 17:51 UTC |