Here a script that illustrates my current workaround:
#! /usr/bin/env perl
use strict;
use warnings;

my $outfile = "file_with_tables.txt";
open(OUT,">$outfile") or die "Couldn't open $outfile for writing: $!\n";
print OUT "Table 1:\n";
_print_format1(1,15,"foo");
_print_format1(2,8,"bar");
close(OUT) or die "Couldn't close $outfile after writing: $!\n";
open(NEWOUT,">>$outfile") or die "Couldn't open $outfile for writing: $!\n";
print NEWOUT "\nTable 2:\n";
_print_format2("clk1", 0.04, 12000, 0.51, 0.39, 0.25);
_print_format2("clk2", 0.13, 27000, 0.8, 0.5, 0.1);
close(NEWOUT) or die "Couldn't close $outfile after writing: $!\n";

sub _print_format1 {
        # output table 1, with 3 columns
        my($id,$num_occur,$msg) = @_;
        format OUT =
        @<<<<<<<<<<<<<< @>>>>>>>>>>>          @<<<<<<<<<<<<<<<<<<<<<<<<<
        $id,            $num_occur,           $msg
.
        write OUT;
}

sub _print_format2 {
        # output table 2, with 6 columns
        my($clock,$skew,$num_ffs,$max_lat,$min_lat,$max_tran) = @_;

        format NEWOUT =
@<<<<<<<<<<<< @>>>>>>>>>>>>>  @>>>>>>>>> @>>>>>>>>>>>>> @>>>>>>>>>>>>>
@>>>>>>>>>>>>>>>
$clock, $skew, $num_ffs, $max_lat, $min_lat, $max_tran
.
        write NEWOUT;
}


Hi,

I think you could open the file once,obtain the filehandle,and pass the filehandle as a paramter to these two subroutines,as:

open(OUT,">$outfile") or die "Couldn't open $outfile for writing: $!\n";
_print_format1(\*OUT,1,15,"foo");
...
_print_format2(\*OUT,"clk1", 0.04, 12000, 0.51, 0.39, 0.25);



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