Andre_br has asked for the wisdom of the Perl Monks concerning the following question:

Oh Thy Wisdom! Allow my humble question!

Hello my friends.

I´d like Perl to unzip a file, but I am not ver familiar with the syntax wich calls unix commands. And also, this one is less newbie and I think may agregate to the site, I'd like to make her wait untill the conversion is finished. Can you guys give me a hand on this?

The script:

my $file = "test.zip"; my $path = "../uploads/46546"; ... command to unix (?) ... then I read the .xls files in the directory with glob and find out +, by elimination, the name of the file the user named his worksheet. +This code is ok already. ... then, I start the parsing, but this (and the code before) cannot h +appen before the conversion is finished, got it? Otherwise Perl won´t + find the file. (?)
I wait for thy help.

Thanks a lot!

André

Replies are listed 'Best First'.
Re: Having Unix to unzip a file and Perl to wait untill it finishes
by holli (Abbot) on Jan 22, 2005 at 20:01 UTC
    You can use Archive::Zip. That way you don´t need any platform dependent external tool.

    holli, regexed monk
Re: Having Unix to unzip a file and Perl to wait untill it finishes
by friedo (Prior) on Jan 22, 2005 at 20:03 UTC
    To execute a command and wait for it to finish you can use system or backticks. (`` or qx//). (see perlop). Each option for executing external programs behaves somewhat differently, so choose with care.
Re: Having Unix to unzip a file and Perl to wait untill it finishes
by johnnywang (Priest) on Jan 22, 2005 at 20:30 UTC
    You can also use Tie::Gzip, something like:
    use Tie::Gzip; tie *CONTENT, 'Tie::Gzip'; open(\*CONTENT, "<$input") or die "Can't open $input\n"; while(<CONTENT>){ ... }

      All well and good, except gzip and Tie::Gzip don't handle .zip (i.e. containing multiple files as the OP says) files . . .