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

I'm trying to run my perl code in c:/myperl and use Archive::Tar routines to build an archive of all files in $vsvroot/cntl/* where $vsvroot is extracted from another process's execution path. //..pad My program appears to insist on seaching its own directory for candidate files instead of searching the directory I want (and thought I'd told) it to.
  • Comment on Archive::Tar from somewhere outside my runtime directory

Replies are listed 'Best First'.
Re: Archive::Tar from somewhere outside my runtime directory
by GrandFather (Saint) on Dec 12, 2011 at 06:17 UTC

    You should read the documentation describing using $tar->setcwd( $cwd ); at the end of the object methods section in the Archive::Tar docs. In part it says:

    Archive::Tar needs to know the current directory, and it will run Cwd::cwd() every time it extracts a relative entry ...
    True laziness is hard work
      This is where my inexperience shows!
      $tar->setcwd($vsvroot); foreach my $vsvxdb (<cntl/*>) { $tar->add_files($vsvxdb); } $tar->write("$vsvroot/tmp/cntlbkup.tar");
      I thought from my reading of the doc that my $tar->setcwd would have caused tar to find all files in the $vsvroot/cntl directory then archive them in $vsvroot/tmp/cntlbkup.tar. I know those files exist but I don't get anything in the archive although the write statement does create it.

        Nope. Reading the docs it looks like setcwd is pure optimisation and that the cwd has to be set for relative paths to do what you expect. However there is an implication that absolute paths are unaffected by such silliness. So, you have two options ...

        True laziness is hard work