Reading a compress'ed file?

Posted on 2005-05-09
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) ) {

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...
Question by:bganoush
    LVL 48

    Expert Comment

    What type of compression?  zip, gzip, compress, bzip2, etc?

    Author Comment



    LVL 48

    Accepted Solution


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

    Author Comment


    Simple solutions show a great wisdom!

    -- Bubba

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
    There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
    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…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    732 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now