Hi guys I managed to resolve the issue regarding the previous issue. First problem - $rows_processed = "rows_processed"; should be : $rows_processed = "rows processed";
After the first WHILE loop, I added a close and open (in this order) of SUMMARYTMP and it worked. Thanks again for the help. Tony -----Original Message----- From: Ho, Tony Sent: 18 April 2002 20:12 To: 'bob ackerman'; [EMAIL PROTECTED] Subject: RE: Writing formatted results to a file Hi Bob, I am having trouble writing another new format into the same file as the one I mentioned in the previous email. I executed the following code and it prints out the SUMMARY format but NOT the SUMMARY1 format into the same file. Any ideas ? Thanks in advance Tony The code is as follows : sub create_summary_report { my (@record, @record_processed, $element, $rows_copied, $rows_processed, $line_output, $oldhandle); @record = qw(A B C D); @record_processed = qw(ACCOUNT); $rows_copied = "rows copied"; $rows_processed = "rows_processed"; $element = 0; open SUMMARYTMP, "<$bcp_file_directory$reports_file_summary_tmp" or die "Unable to open $reports_file_summary_tmp for reading: $!\n"; open SUMMARY, ">$reports_directory$reports_file_summary_final" or die "Unable to open $reports_file_summary_final for writing: $!\n"; print SUMMARY "Extraction Summary Details\n"; print SUMMARY "--------------------------\n"; print SUMMARY "Server : $server\n"; print SUMMARY "Database : $db\n"; print SUMMARY "User : $user\n"; print SUMMARY "Account (From) : $fromAccount\n"; print SUMMARY "Account (To) : $toAccount\n"; print SUMMARY "Start Time : $start_time\n"; print SUMMARY "End Time : $end_time\n\n\n"; print SUMMARY "Record (Bulk Copied)\n"; print SUMMARY "--------------------------\n"; while(<SUMMARYTMP>) { chop; $line_output = $_; if ($line_output =~ /\b$rows_copied\b/) { write(SUMMARY); $element = $element + 1; } } $element = 0; print SUMMARY "\n\nRecord (Processed)\n"; print SUMMARY "------------------------\n"; while(<SUMMARYTMP>) { chop; $line_output = $_; print "$line_output\n"; if ($line_output =~ /\b$rows_processed\b/) { $oldhandle = select(SUMMARY); $~ = "SUMMARY1"; select($oldhandle); write(SUMMARY); $element = $element + 1; } } close SUMMARYTMP or die "Error closing $reports_file_summary_tmp"; close SUMMARY or die "Error closing $reports_file_summary_final"; format SUMMARY = @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $record[$element], $line_output .. format SUMMARY1 = @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $record_processed[$element], $line_output .. } -----Original Message----- From: bob ackerman [mailto:[EMAIL PROTECTED]] Sent: 16 April 2002 19:36 To: [EMAIL PROTECTED] Subject: Re: Writing formatted results to a file On Tuesday, April 16, 2002, at 10:11 AM, Ho, Tony wrote: > Hi guys > I was wondering if you could help me. > Does anybody know how to write formatted results to a file ? > > I am getting the following error : > > write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, > <SUMMARYTMP> line 5. > write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, > <SUMMARYTMP> line 15. > write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, > <SUMMARYTMP> line 21. > > This is the section of my perl code reads results from an BCP output file > and is as follows : > > sub create_summary_report > { > my (@record, $element, $rows_copied, $line_output); > @record = qw(A B C); > $rows_copied = "rows copied"; > $element = 0; > > open SUMMARYTMP, "<$bcp_file_directory$log_file_summary_tmp" > or die "Unable to open $log_file_summary_tmp for reading: $!\n" > ; > > open SUMMARY, ">$log_directory$log_file_summary_final" > or die "Unable to open $log_file_summary_final for writing: > $!\n"; > > print SUMMARY "Summary Details\n"; > print SUMMARY "--------------------------\n"; > print SUMMARY "Account (From) : $fromAccount\n"; > print SUMMARY "Account (To) : $toAccount\n\n\n"; > print SUMMARY "Record Types\n"; > print SUMMARY "------------\n"; > > format ADDRESSLABEL = > @<<<<<, @<<<<< > $record[$element], $line_output > .. > > while(<SUMMARYTMP>) { > chop; > $line_output = $_; > if ($line_output =~ /\b$rows_copied\b/) { > print SUMMARY write(ADDRESSLABEL); > $element = $element + 1; > } > } > in addition you need to quote the format label when assigning: $~ = 'ADDRESSLABEL'; > close SUMMARYTMP > or die "Error closing $log_file_summary_tmp"; > > close SUMMARY > or die "Error closing $log_file_summary_final"; > } > > I would be most grateful with any advice. > > Thanks in advance > Tony > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]