in reply to Re^4: Reading zipped files (.gz)
in thread Reading zipped files (.gz)

My link linked to the documentation of the module. The module comes already distributed with Perl. Why did you try to install it?

Replies are listed 'Best First'.
Re^6: Reading zipped files (.gz)
by ravi45722 (Pilgrim) on Nov 18, 2015 at 09:33 UTC

    As you suggested I changed my ls with File::Glob. Now help me in how to read .gz files???

    #!/usr/bin/perl use warnings; use strict; use File::Glob ':bsd_glob'; use Archive::Tar; use Data::Dumper; my $cdr_dir="/root/prac/NSN_SGSN"; my @list = bsd_glob('*.gz'); print Dumper \@list; foreach my $file (@list) { #open gz file, read line by line }

        How can we use open to read .gz files. I can use to read after unzipping. But I dont want to unzip it. I want to read it directly without unzipping. Is there any modules to do like that???

      You already have been introduced to the concept of reading from pipes. Maybe try

      my $cmd = sprintf 'gzip -cd "%s"', $file; open my $fh, $cmd or die "Couldn't read [$cmd]: $!";

        In the code I am printing the list of files. In that it showing files. But while trying to read it's showing error like this.

        [root@ems NSN_SGSN]# perl gun.pl $VAR1 = [ 'generate_ASR_PSR_report.pl.gz', 'generate_nsn_sgsn_report.pl.gz' ]; Couldn't read [gzip -cd "generate_ASR_PSR_report.pl.gz"]: No such file + or directory at gun.pl line 20.
        #!/usr/bin/perl use warnings; use strict; use File::Glob ':bsd_glob'; use Archive::Tar; use Data::Dumper; my $cdr_dir="/root/prac/NSN_SGSN"; my @list = bsd_glob('g*.gz'); print Dumper \@list; foreach my $file (@list) { my $cmd = sprintf 'gzip -cd "%s"', $file; open my $fh, $cmd or die "Couldn't read [$cmd]: $!"; while ( my $line = <$fh> ) { print $line; } close $fh; }