Re: how to format output



moonhkt wrote:
Hi All

How to format output ? I want output format in io2.txt file.


$fn="io.txt"; # Input file
$fout = ">io2.txt"; # Write to file
$abc="String";
open ( OUTFILE, $fout);
open( IN, $fn) or die (" cannot open in.txt for reading: $!");

format HEADER=
@<<<<<<<<<@<<@<<
$abc$so_type$code

.

while (my $line = <IN>) {
print "$line";
}

print (OUTFILE "Output to file\n");


close ( IN ) or die("Cannot close file: $!");
close (OUTFILE) or die ("Can not close io2.txt");

I have only minimally changed your code. I have purposely tried to touch what you wrote
as little as possible.
If you elaborate on what you want to do I could help
more.

The default naming convention for a format is that it match the filehandle.
If you want the format HEADER to really be the header the default naming convention for that is
to match the format followed by _TOP. In your case
OUTFILE_TOP.

$fn="io.txt"; # Input file
$fout = ">io2.txt"; # Write to file
$abc="String"; # Make sure all your variables
my $line; # used in the format are scoped
# correctly!
open(OUTFILE, $fout);
open(IN, $fn) or die (" cannot open in.txt for reading: $!");

format OUTFILE_TOP=
@<<<<<<<<<@<<@<<
$abc$so_type$code
..

format OUTFILE=
@<<
$line
..

select(OUTFILE);

while ($line = <IN>) {
write;
}

print (OUTFILE "Output to file\n");


close ( IN ) or die("Cannot close file: $!");
close (OUTFILE) or die ("Can not close io2.txt");


.



Relevant Pages

  • Re: SQL binary question
    ... The database does not know the format of the data because it is not defined as separate fields of the output file itself. ... See the help text for the OUTFILFMTor DSPFFD of the current *OUTFILE as the definition of the fixed columns to define. ... The file I am journaling against has a 75 byte per record ...
    (comp.sys.ibm.as400.misc)
  • Re: sort email by date
    ... then use Thunderbird to remove the dupes. ... the header marker is either constant or there are a limited number of them. ... written if full procedural format for ease of conversion to ... close(OutFile) ...
    (comp.lang.awk)
  • how to format output
    ... I want output format in io2.txt file. ... open (OUTFILE, $fout); ... format HEADER= ... close or die; ...
    (comp.lang.perl.misc)
  • Re: how to format output
    ... I want output format in io2.txt file. ... open (OUTFILE, $fout); ... If you want the format HEADER to really be the header the default naming convention for that is ... From the third edition onwards formats are not ...
    (comp.lang.perl.misc)
  • Re: better design of spreadsheet generation
    ... The easiest way is to use printf. ... If you want a plain text spreadsheet, use a format. ... to test printing a heredoc to an outfile ...
    (comp.lang.perl.misc)