in reply to Tar GZip Question

To deal with the .gz extension Compress::Zlib. Right in the documentation, it shows a simple gzip -d snippet via the module. Someone else mentioned Archive::Tar I believe it was. I've never used it, but it sounds like it could be close to what you are looking for. ;)

I am also assuming the system calls I've included below are in fact the perl system functions, as opposed to your own. You dont need to escape the . in system commands. So they can be rewritten like so..
from:
system("mv", "katt0$number\.tar\.gz", "\.\.\/html\/img\/katt0$number\.tar\.gz");
to:
system("/usr/bin/mv ./katt0$number.tar.gz ../html/img/katt0$number.tar.gz");
But that isnt quite perlish enough.. Lets try
my $tarball = "katt0$number.tar.gz"; rename("$tarball", "../html/img/$tarball");
Now on top of that the call to tar will extract the contents of the tarball in the present working directory. I do not know what functionality Archive::Tar will give, but I can almost guarantee that it will allow you to extract the contents to another directory. If not, you'll need play with your ENV hash, and alter the PWD key. There may be a more perlish way to do that, I'm not sure.

At the very least that should get you rolling in the right direction.

/* And the Creator, against his better judgement, wrote man.c */

Replies are listed 'Best First'.
Re^2: Tar GZip Question
by Aristotle (Chancellor) on Oct 30, 2002 at 12:42 UTC
    to:
    system("/usr/bin/mv ./katt0$number.tar.gz ../html/img/katt0$number.tar.gz");
    Err no. You're right he doesn't need to escape the dots of course, but his system LIST form avoids the shell, yours doesn't.
    rename("$tarball", "../html/img/$tarball");

    That is usually better, but don't forget to mention the caveat that mv(1) will work across filesystem boundaries and rename won't. File::Copy is what you usually want when you're using rename. (Oh, and why the quotes around $tarball?)

    Playing with $ENV{PWD} does not do anything other than confuse yourself - it doesn't actually change the working directory. You either want to actually chdir or (as I posted above) use the -C option to tar.

    Makeshifts last the longest.

      I didn;t know about that functionality in regards to the LIST context of the system command..

      I quoted $tarball cause I'm paranoid.. I always quote, or use braces liberally... I'd rather be overly paranoid and make sure the guy coming after me knows exactly what I meant when I wrote it as opposed to leaving some ambiguity...

      And thanks for the chdir ... couldn't remember the function name, but I knew it was buried in there somewhere..

      /* And the Creator, against his better judgement, wrote man.c */
        You won exactly nothing by quoting $tarball though - it doesn't have any noteworthy effect other than making Perl do some extra work to concatenate it into a new string consisting only of the variable's content. You also break references if you try to pass them around like this, and if you don't enable strictures, you're going to accidentally be turning the references into symbolic ones to boot. Perl ain't shell, so don't quote variables when you're not concatenating them into a larger string.

        Makeshifts last the longest.