Writing formatted results to a file

------_=_NextPart_001_01C1E569.B001A870
Content-Type: text/plain;
	charset="iso-8859-1"

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;
          }
     }
 
     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
 

------_=_NextPart_001_01C1E569.B001A870--
0
Tony_Ho
4/16/2002 5:11:03 PM
perl.beginners 29344 articles. 3 followers. Follow

4 Replies
566 Views

Similar Articles

[PageSpeed] 35

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;
>           }
>      }
>

are you trying to send the format to SUMMARY?
then i would think you want something like:
$~ = ADDRESSLABEL;
write(SUMMARY)

no 'print SUMMARY ...'

check perldoc -f write

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

0
rdacker
4/16/2002 5:33:10 PM
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
>

0
rdacker
4/16/2002 5:35:47 PM
------_=_NextPart_001_01C1E56E.ACDBE520
Content-Type: text/plain;
	charset="iso-8859-1"

Hi Bob
Thanks for the help.
I renamed the format label from ADDRESSLABEL to SUMMARY and it appeared to
work also.
Thanks again for the help.
Tony

-----Original Message-----
From: bob ackerman [mailto:rdacker@pacbell.net]
Sent: 16 April 2002 19:36
To: beginners@perl.org
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: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org

------_=_NextPart_001_01C1E56E.ACDBE520--
0
Tony_Ho
4/16/2002 5:46:45 PM
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:rdacker@pacbell.net]
Sent: 16 April 2002 19:36
To: beginners@perl.org
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: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
0
Tony_Ho
4/18/2002 6:12:23 PM
Reply:

Similar Artilces:

writing file::find results to an file
Hi, I'm using file::find to (obviously!) find files, but I want the results to be placed in a text file so I can send the paths via email to others. Could someone have a look at this code (granted it might and is messy), But look at all lines beginning with * (near the bottom) and tell me why it dumps EVERY file it looks at into my text file. Any help would be appreciated. When i just print out the results to the screen, it works, when I try to put it into a file it doesn't... Thanx a zill... ben #!usr/bin/perl -w use File::Find; use File::Basename; $match=<ST...

the file format does not write to the output file
If i run the below code it does not right to the voucher.rtf file. Can you guide on the best way to accomplish this. #!/usr/bin/perl use warnings; use strict; my ($pin, $pin1, $pin2, $val); format MINE= Voucher @<<< Voucher @<<< Voucher @<<< $val, $val, $val, PIN @<<<<<<<<<<<<< PIN @<<<<<<<<<<<<< PIN @<<<<<<<<<<<<< $pin, ...

RE: Writing formatted results to a file
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'; beginners@perl.org 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 men...

formatting and writing to file
I would like to format this so that the parameters and values are listed on their own lines. foreach my $name ( $cgi->param ) { print "$name\t" . $cgi->param( $name ) . "\n"; } This part of the script is not executing. my $file = $cgi->upload( "ad" ) or error( $cgi->p( "No file uploaded." ) ); my $format = $cgi->uploadInfo( $file )->{ 'Content-Type' }; open (TEMP, ">>$tmpdir/tmpfile.fil") or die "Can't find tmpfile.fil"; print TEMP "$format \n"; print TEMP "$fi...

Writing the result of a query to a file
I currently have a dynamic query builder in ASP that the user can display the results of the query in a table or dump to a double-quote qualified, coma-delimited file. (to save as a .csv or whatever) I'm in the process of rebuilding the application in .NET, but have not be able to figure out how to write to the file in this mannor. Before it seemed quite simple using set and looping through all the entries writing a line at a time, but how do you do this in .NET. Below I have my code, which is very similar to how I populate my datagrid for the same query, but in this ...

Writing file to browser needs write permissions to show file
 Hi all, I have a page called GetFile.aspx which does the simple job of converting the aspx document into either a word or PDF file for downloading of viewing online (dependant on user browser settings) but im having an issue where the file im including must have write access for it to be opened and shown in the browser.   Dim fs As New FileStream(FileName, FileMode.Open) Using (fs) Dim data() As Byte = New Byte(fs.Length) {} Dim br As BinaryReader = New BinaryReader(fs) br.Read(data, 0, data....

Write Qry results to file
I'd like to create an event to dump a query result to a file on a daily basis. From ISQL, this works great: SELECT ... FROM mytable; OUTPUT TO myfile FORMAT ASCII; But, the OUTPUT statement only works in ISQL. Is there something comperable that works elsewhere? My only other option that I can find is to use ISQL in a batch mode and invoke it from a OS command. Yuck. Thanks! Using SQLA 9.0.2.something x64 edition on WinServer 2003 x64 See UNLOAD SELECT. Caution: the file spec is relative to the computer running the database engine, whereas with ISQ...

Converting windows txt file format to Linux txt file format
------_=_NextPart_001_01C1BB0F.C70965F0 Content-Type: text/plain; charset="iso-8859-1" Hi everyone I am trying to upload a windows txt file to a Linux server. There are an application running in my Linux server that reads the txt file to extract some information. But the application doesn't recognize the file because it's originally from windows. I know that I could solve it changing the end of line caracters such as line feed and carriage return, but I don't know how to do it. Does anyone know a way to do it using Perl? Thanks in advance. Li...

Eof of file , file read and file write ! Problem !
Hello All, I want to do 2 things. I have a big file and I want to read file line by line upto last. and side by side i want to write it to new file with some change I am not getiing , in a read , linemode! how i will get End of file and how i will do all this. can you tell me script. I'm not sure I understand your question. From the PowerBuilder Help file, in linemode! FileRead() will return a 0 when it reaches End of File (EOF) so it should be trivial to code? This is just off the cuff but I would imagine it's something like li_Readfile = FileOpen( ...

Writing Query Result to txt File
I'm trying to write the results of a query to a text file on the server. I'm able to write the file successfully, but I do not know the syntax to write the contents of a query or recordset to the text file. Could someone show a simple example of how I'd do this? thanks! i usually use: 1; John Doe; New York2; Rick James; Detroit3; Charlie Murphy; Los Angeles  James Hearst.NET Application Developer Have you tried using an old FileSystemObject.  This has all the functions to create files and write away records on your own server. BlueMistOnline, What do you mean? c...

want to write to file in different format
--_5b8ce28a-3107-438c-bba5-8b79e755fec1_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I have a file of contents: ----------- 1 6 2 7 3 8 4 9 5 10 ---------- I want a file with content: 1 2 3 4 5 6 7 8 9 10 -------- I have written a few lines of following code but it does not work as expect= ed : ------------------------------------------- #!/usr/bin/perl use v5.10=3B use strict=3B use warnings=3B open(FILE=2C "numbers.txt") or die "can not open file . $!\n"=3B open(FILE1=2C ">s...

writing to a file in a well formatted way
i am using visual web developer 2005 and SQL Express 2005 with VB as the code behindi want to send invoices to customersi have to dynamically retrieve information for customers and write them to a well formatted files (like a HTML page)and send that to customersi want my file to look like the one belowthose details like customer no. , order no. , order received date etc which are specific to individual  customersmust be dynamically retrieved fro the database and written to file in the below formatthis file must be uploaded to the customers mail as attachmenti don't have problem in ...

Writing a resulting aspx HTML as a file...
I want to write my http://loclahost/myFancyApp/log.aspx?id=#### file when my code executes it to write it to a lcoal file as C:\INetPub\WWWroot\myfancyApp\logs\#####.html ? Any one know how to do that? Thank you!==========Nikita MVP========== you mean you wanto to create an html file ? can you xplain a little more on what you are trying to do ?***********************Dinakar NethiLife is short. Enjoy it.*********************** I want to have code create a html file to be 1-1 of what i see when i load my log.aspx?id=123 from the browser Basically, i want it to view source and save...

Writing DataWindow Results to a PDF File
I have been trying to write DataWindow results to a PDF file. We are using PowerBuild 8.0 with AdobePS Acrobat Distilled. I've tried some code that I downloaded from the web (see Power Script below). All that ever happens is that the document just gets sent to my default printer. I've traced it all through the PB debugger and all the registry settings are being set correctly. Am I missing something? Are there any printer properties that need to be set? // Power Script String is_PrinterRegKey = & "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Wi...

Web resources about - Writing formatted results to a file - perl.beginners

Formatted text - Wikipedia, the free encyclopedia
Formatted text cannot rightly be identified with binary files or be distinct from ASCII text. This is because formatted text is not necessarily ...

Received a badly formatted email on your mobile? 75 percent of you will delete it
A survey by Constant Contact shows that mobile devices are more important than ever, particularly to those under the age of 30. The study reveals ...

Quickly view formatted PDFs in your search results
Google search results sometimes include documents that were not originally formatted to be viewed in a web browser, such as PDFs. In the past, ...

Now in Google search results: Formatted PDFs
Google has launched a new search option called Quick View that allows users to open formatted PDF filesnot just HTML viewing of documentsfrom ...

Proxy ports showing formatted text in Mountain Lion
An interface bug in the OS X Network system preferences shows unconventional port string formats, but does not affect OS X performance.

It’s Markdown, no, PowerShell. Wait its Markdown formatted PowerShell.
... "Current DateTime is = $([System.DateTime]::Now)" ### Escape characters with the ` (back-tick) "Escape a quotation `"This is quoted`"." Formatted ...

Exploit can control older Macs even after they're formatted
Exploit can control older Macs even after they're formatted

HBO cancels 'In Treatment' 'as previously formatted'
HBO just made it official: In Treatment will not return for a fourth season. The psychotherapist drama won plenty of critical acclaim and Emmy ...

FAA GPS data formatted for your use
[Michael] posted up-to-date GPS data sets in the GPX format . These data sets are an alternative to paid updates. Since GPX is a published standard ...

Converting Mac-formatted iPod to Windows - iLounge Article
Q: In reading your FAQ and previous columns, I see that it is possible to use a Mac-formatted iPod on a Windows PC through the use of a third-party ...

Resources last updated: 12/29/2015 8:21:14 PM