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

The following code only archives $this_file, and the original contents of the tar file are lost. What am I doing wrong?
The problem seems to relate to the remove function, but I don't understand why, since I've already written to the tar file by that point.
#!/usr/local/bin/perl use Archive::Tar; # handles tar files my $lab_tar = Archive::Tar->new(); my $this_file = $ARGV[0]; my $tar_file = "foo.tar"; if(-e $tar_file){ print "found archive\n"; $lab_tar->read($tar_file); print $lab_tar->list_files(); print "\n"; } $lab_tar->add_files($this_file); print $lab_tar->list_files(); print "\n"; $lab_tar->write($tar_file); $lab_tar->remove($lab_tar->list_files()); #unlink $this_file;
Tom Melly, tom@tomandlu.co.uk

Replies are listed 'Best First'.
Re: Tar help
by fs (Monk) on May 31, 2001 at 18:26 UTC
    The code you put here Work For Me(TM), which suggests to me that you're running into some error condition along the way (file not found, out of disk space/memory, etc). Try checking for errors along the way as you go - the Archive::Tar docs tell you how to retrieve any errors.
      Hmm, and it works for me under win2000. It just fails on 2 aix servers I tested it on. Still, at least the code is okay. I shall investigate further.
      Thanks for your time.
      Tom Melly, tom@tomandlu.co.uk