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

Hello Monks,
I am using LWP module to download a file
but the file which i downloaded is a zip file i need to unzip that file so that i can use
i am using windows xp and WINRAR to unzip it.
#!/usr/bin/perl use LWP::Simple; my $url = "http://www.xyz/sql.gz"; my $file = "xyz.sql"; # get the data is_success(getstore($url, $file)) or die "Mark probably broke the server again!\n";
I need to do it so that i can make my application update easily.

Replies are listed 'Best First'.
Re: how can i unzip a file
by johngg (Canon) on Nov 26, 2007 at 21:31 UTC
    You could have a look at Archive::Zip which will do what you want.

    Cheers,

    JohnGG

Re: how can i unzip a file
by tuxz0r (Pilgrim) on Nov 26, 2007 at 20:54 UTC
    My guess is you're asking how to call WINRAR via the perl script. This is easy with a system() call, as such (I don't know WINRAR syntax, so I'll just use gzip):
    my @args = ("gunzip", "$file"); my $rv = system(@args); die "system @args failed: $?" if ($rv != 0);
    In your case, you'd just make "gunzip" the executable name for WINRAR, and pass in any other arguments besides the local file name to unzip as extra items in the @args list in the correct order as on the command line.

    ---
    echo S 1 [ Y V U | perl -ane 'print reverse map { $_ = chr(ord($_)-1) } @F;'
    Warning: Any code posted by tuxz0r is untested, unless otherwise stated, and is used at your own risk.

Re: how can i unzip a file
by j1n3l0 (Friar) on Nov 26, 2007 at 22:20 UTC
    You may also want to look at Compress::Zlib ... which is in the standard module library =)


    Smoothie, smoothie, hundre prosent naturlig!
Re: how can i unzip a file
by aquarium (Curate) on Nov 26, 2007 at 22:01 UTC
    windows xp has built in "compressed folders", which is just a fancy way of saying built in zip/unzip, with Explorer being able to see inside. Anyway, calling "unzip" with system call works...if you don't care about portability.
    the hardest line to type correctly is: stty erase ^H
Re: how can i unzip a file
by Popcorn Dave (Abbot) on Nov 27, 2007 at 04:09 UTC
    Another monk will correct me if I'm wrong on this, but I think you need to change to binary mode before you download said file. Of course using the modules that others have suggested you use to do what you're trying to do may not require the binary switching before.


    Revolution. Today, 3 O'Clock. Meet behind the monkey bars.

    I would love to change the world, but they won't give me the source code