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

This node falls below the community's minimum standard of quality and will not be displayed.
  • Comment on How do i change the file names while untar?

Replies are listed 'Best First'.
Re: How do i change the file names while untar?
by Zaxo (Archbishop) on Sep 28, 2005 at 15:11 UTC

    On unix, the location should be /test1/test2.txt, with forward slashes.

    If you use Archive::Tar, you can rename any files you like with the rename method.

    use Archive::Tar; my $tar = Archive::Tar->new('tarball.tgz', 1) or die $!; $tar->rename($_, changepath($_)) for $tar->list_files; $tar->extract;
    where changepath() returns whatever transformed path you need (untested).

    File::Spec may be useful in constructing changepath().

    After Compline,
    Zaxo

      Wow, that was an elegant api. Thanx for info!

      (I knew about Archive::Tar but have never had a reason to look at it.)

      Thanks a lot Zaxo, I tried to rename but I am getting errors: my $tar = Archive::Tar->read('test.tar', 1) or die $!; $tar->rename($_, '/export/home/test/renametest') for $tar->list_files; print ("$_"); I am getting the errors: Can't call method "list_files" without a package or object reference. and similar message for rename...Any suggestions?

        Try omitting the compression flag since you are dealing with an uncompressed tarball, and call new as the constructor,

        my $tar = Archive::Tar->new('test.tar') or die $!;

        That will make $tar an Archive::Tar object whose methods will be found.

        After Compline,
        Zaxo

Re: How do i change the file names while untar?
by marto (Cardinal) on Sep 28, 2005 at 15:04 UTC
    I must be missing the part in your question where you tell us how Perl is involved in this.
    Have you read the tar documentation to find out how to use it properly?
    Take a look at How do I post a question effectively? and the PerlMonks FAQ if you have not done so already.

    Martin