Question : Perl gunzip

Hi,

I am trying to gunzip a file in perl and it seems to not work. Below is the logic.......

    $subFile = getInputFile( $jobNum );
    $subFile = system("/usr/bin/gunzip $subFile");
            
   if(substr($subFile, length($subFile)-2,2) eq '.gz')
   {
         "/usr/bin/gunzip $subFile";                                  
          $subFile=substr($subFile, 0, length($subFile)-2);        
   }
    print STDOUT "\n\tInput file:    $subFile";

Please advise...

Thanks,
Mohammed

Answer : Perl gunzip

"seems to not work" is an incredibly vague description as to the problem.

Try:

$subFile = getInputFile( $jobNum );

if ($subFile =~ /\.gz$/) {
  system "/usr/bin/gunzip $subFile" and die "gunzip $subFile failed $!\n";
  $subFile =~ s/\.gz$//;
}

print "\n\tInput file: $subFile\n";


Random Solutions  
 
programming4us programming4us