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

Hello

I want to take an original $parent_tar object in memory and create sub-set $child_tar objects, without having to write intermediately to disk.

Looking in the documentation, the only method that lets you directly manipulate the in-memory archive is $tar->remove, and the $tar->get_files() method returns Archive::Tar::File objects that don't seem to fit into new $tar objects.

Also, for the $children_tar's, do I have to instantiate multiple objects from the original tar file, then clear them, to accept the subsets?

Thanks!

Replies are listed 'Best First'.
Re: Splitting up Archive::Tar $tar object
by flounder99 (Friar) on Sep 03, 2003 at 19:07 UTC
    Does this example answer your quiestion?

    paste this into temp.pl

    use Archive::Tar; use strict; my $parent = Archive::Tar->new("parent.tar"); my $child_tar = Archive::Tar->new(); $child_tar->add_data("file1",$parent->get_content("file1")); $child_tar->add_data("file2",$parent->get_content("file2")); $child_tar->write("child1.tar"); $parent->remove("file1"); $parent->remove("file2"); $parent->write("child2.tar");
    then run
    $ echo "contents of file1">file1 $ echo "contents of file2">file2 $ echo "contents of file3">file3 $ echo "contents of file4">file4 $ tar cf parent.tar file? $ rm -f file? $ perl temp.pl $ tar xfv child1.tar file1 file2 $ cat file? contents of file1 contents of file2 $ tar xfv child2.tar file3 file4 $ cat file? contents of file1 contents of file2 contents of file3 contents of file4

    --

    flounder

Re: Splitting up Archive::Tar $tar object
by gft28 (Initiate) on Sep 03, 2003 at 19:40 UTC
    Gracias, Flounder...that does it.