Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Archive::Tar and write to an open filehandle

Reply
Thread Tools

Archive::Tar and write to an open filehandle

 
 
Andrew Hamm
Guest
Posts: n/a
 
      10-09-2003
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


 
Reply With Quote
 
 
 
 
Jens M. Felderhoff
Guest
Posts: n/a
 
      10-09-2003
"Andrew Hamm" <> wrote:

> 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
--
(Intentionally left blank.)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
perl Write filehandle blocks. kiranmn@my-deja.com Perl Misc 6 05-02-2007 08:17 PM
is better to open, write, close file than open, write, append, close? Iulian Ilea Javascript 1 12-21-2006 04:32 PM
use print to write binary data to a filehandle seems not correct quakewang@mail.whut.edu.cn Perl Misc 6 11-22-2006 06:30 PM
MIME::Entity attaching from an open filehandle? Matthew Braid Perl Misc 1 02-11-2004 01:58 AM
Write to a filehandle and to STDOUT without double print statements? dnrg Perl Misc 5 06-26-2003 04:39 PM



Advertisments