#!/usr/bin/perl # # Sample test script # use strict; use warnings; use Archive::Tar; use File::Find; $Archive::Tar::DEBUG=1; my $srcDir = 'C:\Temp\data'; ## Attempt 1 - add the files to the archive in the callback code. my $archive = Archive::Tar->new(); find(\&callback1, $srcDir); $archive->write('one.tar.gz', 9); print "---------ONE-------------------\n"; print join("\n", $archive->list_files()); print "---------ONE-------------------\n"; ## Attempt 2 - prepare a list of files and add to the archive in one place my @files = (); # not using $archive->clear() - I want this to be independent of previous # attempt $archive = Archive::Tar->new(); find(\&callback2, $srcDir); $archive->create_archive('two.tar.gz', 9, @files); print "---------TWO-------------------\n"; print join("\n", @files); print "---------TWO-------------------\n"; sub callback1() { $archive->add_files($File::Find::name); } sub callback2() { push(@files, $File::Find::name); } #### ---------ONE------------------- C:/Temp/data C:/Temp/data/SpaceMonger.exe C:/Temp/data/spacemonger_README.TXT C:/Temp/data/tcpvcon.exe C:/Temp/data/bar C:/Temp/data/bar/Tcpview.exe C:/Temp/data/bar/TCPVIEW.HLP C:/Temp/data/bar/tcpview_README.TXT C:/Temp/data/foo C:/Temp/data/foo/nc.exe C:/Temp/data/foo/nc_license.txt C:/Temp/data/foo/nc_readme.txt---------ONE------------------- ---------TWO------------------- C:\Temp\data C:\Temp\data/SpaceMonger.exe C:\Temp\data/spacemonger_README.TXT C:\Temp\data/tcpvcon.exe C:\Temp\data/bar C:\Temp\data/bar/Tcpview.exe C:\Temp\data/bar/TCPVIEW.HLP C:\Temp\data/bar/tcpview_README.TXT C:\Temp\data/foo C:\Temp\data/foo/nc.exe C:\Temp\data/foo/nc_license.txt C:\Temp\data/foo/nc_readme.txt---------TWO-------------------