Archive::Tar and write to an open filehandle

A

Andrew Hamm

Perl 5.8.0
Archive::Tar 1.05

The doco for the write method says:

$tar->write ( [$file, $compressed, $prefix] )
Write the in-memory archive to disk. The first argument
can either be the name of a file or a reference to an
already open filehandle (a GLOB reference). If the second
argument is true, the module will use IO::Zlib to write
the file in a compressed format. If IO::Zlib is not
available, the "write" method will fail and return.

But using either of these:

open FH, "| filter" or die "cannot pipe to filter: $!\n";
my $fh = IO::File->new("| filter") or die "cannot pipe to filter: $!\n";

with any of these:

$tar->write(*FH);
$tar->write(\*FH);
$tar->write($fh);

I just end up with a file called 'GLOB(hexnum)' or 'REF(hexnum)' or
'IO::File=GLOB(hexnum)'.

What am I missing/mis-understanding?

TIA
 
J

Jens M. Felderhoff

Andrew Hamm said:
Perl 5.8.0
Archive::Tar 1.05

I have 0.22, however...
The doco for the write method says:

$tar->write ( [$file, $compressed, $prefix] )
Write the in-memory archive to disk. The first argument
can either be the name of a file or a reference to an
[...]

But using either of these:

open FH, "| filter" or die "cannot pipe to filter: $!\n";
my $fh = IO::File->new("| filter") or die "cannot pipe to filter: $!\n";

I don't know why you'll want to write to a pipe. With my Archive::Tar
version writing to a pipe gives a

Can't call method "gzwrite" on unblessed reference at
/usr/lib/perl5/site_perl/5.005/Archive/Tar.pm line 521.
with any of these:

$tar->write(*FH);
$tar->write(\*FH);
$tar->write($fh);

I just end up with a file called 'GLOB(hexnum)' or 'REF(hexnum)' or
'IO::File=GLOB(hexnum)'.

Try something like the following:

$tar->add_files("foo", "bar", "froz", "foobar");
open TARFILE, ">foo.tar" or die "Cannot open tarfile:$!\n";
$tar->write(*TARFILE{IO}); # or \*TARFILE or *TARFILE{FILEHANDLE}
close TARFILE;

That should give you a foo.tar file including the four archive
members.

Cheers

Jens
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top