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

Okay, I assume I am missing something if I run the following:

use strict; use warnings; use Archive::Tar; use File::Find; my @files; my $pwd = 'C:\Source Code'; find( sub { if ( $File::Find::name !~ /\.svn/i) { push @files, $File::Find::name; } }, $pwd ); Archive::Tar->create_archive( 'Test.tbz', COMPRESS_BZIP, @files ); my $tar = Archive::Tar->new; $tar->write('Test2.tbz', COMPRESS_BZIP); $tar->add_files(@files);

The Test.tbz file is created fine with no issues and ends up about 92M.

But when it comes to the Test2.tbz file, I can watch it grow as it should but then before the $tar->add_files(@files); returns the output file shrinks and ends up only about 1k.

I can not figure out what is going wrong I have tried going through the Archive::Tar to try figuring out what I should be doing. But I am getting no where

Replies are listed 'Best First'.
Re: Issue with Archive::Tar
by GotToBTru (Prior) on Mar 21, 2014 at 15:32 UTC

    The write method writes the in-memory archive to disk. You haven't added the files to it yet, so it is writing an empty archive to disk. Reverse your last two steps.

Re: Issue with Archive::Tar
by Bloodnok (Vicar) on Mar 21, 2014 at 15:33 UTC
    It rather looks to me as tho' you're writing before there's anything there i.e.
    $tar->write('Test2.tbz', COMPRESS_BZIP); $tar->add_files(@files);
    should be
    $tar->add_files(@files); $tar->write('Test2.tbz', COMPRESS_BZIP);
    Referring to Archive::Tar, we see that add_files() only adds files to the in-memory object i.e. not to any file that may have been written using write() ... unless, of course, it's nealry beer o'clock on Friday afternoon and I've missed something even more elementary :-)

    A user level that continues to overstate my experience :-))

      Knew I was overlooking the obvious.

      Thanks

        Not a problem dracos, we all do it ... and I defy anybody to say they don't :-)

        A user level that continues to overstate my experience :-))