in reply to Re^2: help with Archive::tar
in thread help with Archive::tar

the tarball would be named something like 81334567-JX4578.tar and when i untar it on the solaris box it would look like 81334567-COMPLETE/toc, 81334567-COMPLETE/<next file>, etc.

That means this particular tar ball contains a directory called "81334567-COMPLETE", and the file you want to extract is inside that directory. You need to pass "81334567-COMPLETE/toc" as first arg in the "extract_file" call.

To do that in a programmatic way -- without having to hard-code the directory name for each tar file -- you could try something like this:

#!/usr/bin/perl use strict; use Archive::Tar; my $wdir = "U:/EMM loads"; # load an array of tar file names: open( DIR, $wdir ) or die "$wdir: $!"; my @tarballs = grep /\.tar$/, readdir DIR; closedir DIR; # for each tar file, yank out the "toc" file: for my $tarball ( @tarballs ) { my $tar = Archive::Tar->new( "$wdir/$tarball" ); my ($toc) = grep { $_->name =~ m{/toc$} } $tar->get_files; # make up a local name for this toc file, based on the tarball name: ( my $tocname = $tarball ) =~ s/tar$/toc/; # write the toc file data to the local toc file: open( TOC, ">", $tocname ) or die "$tocname: $!"; print TOC $toc->get_content; close TOC; }

Replies are listed 'Best First'.
Re^4: help with Archive::tar
by paulehr (Sexton) on Apr 03, 2006 at 12:20 UTC
    Thank you for the examples, I am going give this a whirl today when i get into work!
      Actually, on second thought -- depending on the number of data files in your tar files, it might be quicker if you replace this line:
      my ($toc) = grep { $_->name =~ m{/toc$} } $tar->get_files;
      with this short-circuit loop:
      my $toc = undef; for my $file ( $tar->get_files ) { if ( $file->name =~ /toc$/ ) { $toc = $file; last; } } ( defined $toc ) or do { warn "no toc file in $wdir/$tarball\n"; n +ext };
      That assumes that the first time you see "toc" as the file name, this is the actual "toc" file that you want. (It also checks for the case where a tarball lacks a "toc" file.)

        Hello graff,
        I got a chance to check out the code that you posted. However when it hits line 25 I am getting a message that there was a checksum error and blows up at this point.
        Here is the output mess when i run the script:

        C:\Documents and Settings\paul.ehrenreich\Desktop>cdload.pl &#963;Æ/&#9575;&#915;>&#9579;&#9619;wi&#8592;l&#8730;&#9556;a1ÅmLú&#88 +05;&#8252;û&#8594;â&#9500;>&#9556;&#9787;&#9786;&#9829;é§: checksum e +rror at C:\Documents and Settings\p aul.ehrenreich\Desktop\cdload.pl line 25 Invalid header block at offset unknown at C:\Documents and Settings\pa +ul.ehrenre ich\Desktop\cdload.pl line 25 ^Wæ&#9565;&#8597;&#8993;ç&#9604;}b&#9557;&#8592;c÷&#8593;&#9571;&#937; +!&#8593;&#8319;&#8594;íÑ&#9560;w ZUu¿ W&#9786;&#9566;L&#9561;DÄ +y&#9578;&#8976;W&#8734;Yß¡&#8595;·÷&#9524;-&#9573;t>[&#9500;&#9557;o& +#9612;&#9632;J&#9474;&#964;M&#9794;µ &#9580;f~&#9492; &#9555;&#9604;ñ&#8597;&#9829;&#9829;&#8992;&#8595;&#8 +993;ó1R&#8596;&#9508;u&#8729;&#8735;&#8734;Lúj&#9556;%ÿ7å: checksum e +rror at C:\Documents and Settings\pau l.ehrenreich\Desktop\cdload.pl line 25 Read error on tarfile (missing data) '0081354308-JY6097/toc' at offset + unknown a t C:\Documents and Settings\paul.ehrenreich\Desktop\cdload.pl line 25

        I am pretty much lost at this point,