Advertisement
hakonhagland

gunzip-text-file-perl

Oct 9th, 2021
1,719
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.71 KB | None | 0 0
  1. use strict;
  2. use warnings;
  3. use Excel::Writer::XLSX;
  4. use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
  5. use Data::Printer;
  6. {
  7.     my $output_fn = 'result.xlsx';
  8.     my $input_fn = 'input.txt.gz';
  9.     my $workbook = Excel::Writer::XLSX->new( $output_fn );
  10.     my $worksheet = $workbook->add_worksheet();
  11.     my $zip = IO::Uncompress::Gunzip->new( $input_fn )
  12.       or die "gunzip failed: $GunzipError\n";
  13.  
  14.     my $col = 0;
  15.     my $row = 0;
  16.     while (!$zip->eof()) {
  17.         my $line = $zip->getline();
  18.         chomp($line);
  19.         next if $line !~ /\S/;  # skip empty lines
  20.         my $value = $line;
  21.         $worksheet->write( $row, $col, $value );
  22.         $row++;
  23.     }
  24.     $workbook->close();
  25. }
  26.  
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement