I need to change my routine and get the final outgz file. I am trying to figure out what is the best way for a gzip processed file to be called inside the perl routine.
For example, I have a routine that creates a file (extract_data). Here's the main loop and subroutine:
foreach my $tblist (@tblist)
{
chomp $tblist;
extract_data($dbh, $tblist);
};
$dbh->disconnect;
sub extract_data
{
my($dbh, $tblist) = @_;
my $final_file = "/home/proc/$node-$tblist.dat";
open (my $out_fh, '>', $final_file) or die "cannot create $final_file: $!";
my $sth = $dbh->prepare("...");
$sth->execute();
while (my($uid, $hostnm,$col1,$col2,$col3,$upd,$col5) = $sth->fetchrow_array() ) {
print $out_fh "__my_key__^A$uid^Ehost^A$hostnm^Ecol1^A$col1^Ecol2^A$col2^Ecol3^A$col3^Ecol4^A$upd^Ecol5^A$col5^D";
}
$sth->finish;
close $out_fh or die "Failed to close file: $!";
};
Am I doing gzip inside main or with sub? What is the best way to do this? Then my new file will be$final_file =/home/proc/$node-$tblist.dat.gz
thank.
source
share