in reply to Opening and reading .gz file

i'm trying to open and read a .gz file.....any ideas on how to do this?

Try

my $file = "file.gz"; open(IN, "gzcat $file |") or die "gunzip $file: $!"; while ( <IN> ) { ... } close(IN);
See perldoc -f open for more details.

You might want to specify the full patch to gzcat if there's a possibility that someone might sneak a trojan horse into your PATH.


Update: s/gunzip/gzcat/

Replies are listed 'Best First'.
Re: Re: Opening and reading ,gz file
by bluto (Curate) on Aug 22, 2002 at 21:50 UTC
    Remember to use the '-c' flag or you will just uncompress the file and get no input at all.

    open(IN, "gunzip -c $file |") or die "gunzip $file: $!";

    bluto