I'm pleased you found the module review, and I'm sorry it wasn't more clear. (Let me know if you have any suggestions for changes/additions.)

If you are always extracting the full content of each tar file to some specific place, then this might be a more efficient approach -- note that I'm assuming the tar file name ends in ".tar" or ".tar.gz" or ".tgz", and I'm stripping that off when naming the directory under EXTRACTED -- personally, I think that having directories named foo.tar.gz and so on is a bad idea:

foreach ( @sorted ) { my $tar = Archive::Tar->new($_); ( my $dest = "./EXTRACTED/$_" ) =~ s/\.t(?:ar(?:.gz|gz)//; mkdir $dest unless ( -d $dest ); chdir $dest or die "mkdir/chdir failed on $dest: $!"; $tar->extract(); # no params: extract full content to cwd chdir "../.."; # return to original cwd }
If you really wanted to extract each file individually for some reason (e.g. to divvy them out different extraction paths depending on some feature), then your loop over files would work better this way:
for my $file ( $tar->get_files ) { my $dataref = $file->get_content_by_ref; # open a suitable output file and print $$dataref to it. # You can use $file->name to see the tarred path and # make subdirs as you see fit. }
Of course, if the tar files are small and/or there are few files involved, you probably won't notice a difference relative to the "list_files() ... extract_file()" approach. (I just noticed it on tar files containing thousands of data files.)

In reply to Re: Archive::Tar extract_file by graff
in thread Archive::Tar extract_file by cajun

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.