in reply to Re: Archiving a directory and its contents with Archive::Tar
in thread Archiving a directory and its contents with Archive::Tar

The compiled "tar" command itself (gnu version -- the de facto standard) is available for every major OS type/version.

Windows does not come with any tar command, neither GNU nor any other implementation. Using the core Archive::Tar seems reasonable there. Especially if there is some braindead corporate policy that disallows installing third party software, except of course those that has been blessed by an incompetent committee.

I don't have much experience with Solaris, but I would not bet a cent that Solaris' default tar is GNU tar. I would rather expect it to be some legacy implementation with a very different behaviour. Sure, Solaris has GNU tools, either out of the box or via sunfreeware.org. But they aren't the default, and they are installed in places where the average Linux user would never look for them. Again, using Archive::Tar makes live easier. You don't have to remember that tar is /usr/ucb4/sunfreeware/gnu/current/bin/tar (or something like that) if $^O=~/sun|solaris/i, and /bin/tar, /usr/bin/tar or just the first tar found in $ENV{PATH} (except, of course, if $^O=~/win/i).

Besides, I think OS/2 did not come with a tar implementation, and I'm sure many other non-Unix operating systems don't have tar, either. And if they do, their tar may behave very different from what you expect after working (too) long with GNU tar.

So, there are reasons to use Archive::Tar, even if it is slow and eats lots of memory.

And to solve the riddle why Archive::Tar does not add the contents of a directory when it's add_files() method is called with a directory name: RTFM! add_files() needs a list of files (including the directories), not a directory name. Use glob or File::Find to build that list.

Also note that Archive::Tar comes with a ptar (Perl TAR) utility, from where you can extract the relevant code.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re^3: Archiving a directory and its contents with Archive::Tar
by vendion (Scribe) on Jun 20, 2009 at 14:11 UTC
    Using Tar is no problem for me, but if I really wanted to use tar then I would have just wrote a bash script to do what I am trying to do instead I went with Perl to get the experience. The reason I tried to just point it to a directory was to see if it would act like Tar in the way that it would archive the contents of the directory automatcally then when that failed I knew what I had to do but don't know how to do it with out hard coding anything because the contents of the directory and subdirectories that I am wanting to archive are guaranteed to change that would mean every time I want to run the perl script i would have to rewrite it for the changes.