Archive::Tar and write to an open filehandle

Discussion in 'Perl Misc' started by Andrew Hamm, Oct 9, 2003.

  1. Andrew Hamm

    Andrew Hamm Guest

    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
    Andrew Hamm, Oct 9, 2003
    #1
    1. Advertising

  2. "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.)
    Jens M. Felderhoff, Oct 9, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Claudio Grondi
    Replies:
    4
    Views:
    552
    Claudio Grondi
    Aug 20, 2005
  2. Ray Van Dolson
    Replies:
    0
    Views:
    320
    Ray Van Dolson
    Sep 23, 2009
  3. Ray Van Dolson
    Replies:
    0
    Views:
    817
    Ray Van Dolson
    Sep 25, 2009
  4. Whitey Johnson

    Output of tar to a filehandle

    Whitey Johnson, Nov 4, 2004, in forum: Perl Misc
    Replies:
    5
    Views:
    125
    Tad McClellan
    Nov 5, 2004
  5. benoit Guyon
    Replies:
    2
    Views:
    218
    benoit Guyon
    Jul 26, 2005
Loading...

Share This Page