?
Solved

Reading a compress'ed file?

Posted on 2005-05-09
4
Medium Priority
?
174 Views
Last Modified: 2010-03-05

I have a subroutine in Perl that reads a file and processes its contents like this:

  my $fh = new FileHandle;
  open($fh, $some_file) || return;
  while( read($fh, $buf, 1024) ) {
      &process(&buf);
  }
  close($fh);

Pretty simple?  Well now I need to open and read a file that is compressed. What's the best way to handle this?  By the way, my file is really big, even compressed, so I'd like to NOT make a copy of it if that's possible.

-- Bubba
-- Put the lime in...
0
Comment
Question by:bganoush
  • 2
  • 2
4 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 13963558
What type of compression?  zip, gzip, compress, bzip2, etc?
0
 

Author Comment

by:bganoush
ID: 13987991

Compress.

0
 
LVL 48

Accepted Solution

by:
Tintin earned 1000 total points
ID: 13992905

open $fh, "/usr/bin/zcat $some_file |" or die "Can not run zcat $!\n";
...
0
 

Author Comment

by:bganoush
ID: 13995654

Simple solutions show a great wisdom!

-- Bubba
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question