pod2usage() if $options{help};
pod2usage({verbose=>2}) if $options{man};
-use IO::Uncompress::Gunzip;
-
$DEBUG = $options{debug};
if (not exists $options{regex}) {
push @ARGV,undef;
}
+sub open_compressed_file {
+ my ($file,$encoding) = @_;
+ $encoding //= ':encoding(UTF-8)';
+ my $fh;
+ if (not defined $file) {
+ $fh = \*STDIN;
+ binmode($fh,':encoding(UTF-8)');
+ return $fh;
+ }
+ my $mode = "<$encoding";
+ my @opts;
+ if ($file =~ /\.gz$/) {
+ $mode = "-|$encoding";
+ push @opts,'gzip','-dc';
+ }
+ if ($file =~ /\.xz$/) {
+ $mode = "-|$encoding";
+ push @opts,'xz','-dc';
+ }
+ if ($file =~ /\.bz2$/) {
+ $mode = "-|$encoding";
+ push @opts,'bzip2','-dc';
+ }
+ open($fh,$mode,@opts,$file);
+ return $fh;
+}
+
my %postfix_ids;
for my $file (@ARGV) {
- my $fh = IO::Uncompress::Gunzip->new(defined $file ? $file:\*STDIN,
- MultiStream => 1,
- Transparent => 1,)
- or die "IO::Uncompress::Gunzip failed: $IO::Uncompress::Gunzip::GunzipError";
+ my $fh = open_compressed_file($file);
while (<$fh>) {
chomp;
my $line = $_;