Hello wise monks,

I have been trying to write a foreach loop in order to untar multiple tar.gz files that I (will) have in a directory. The script I've written is

#/bin/perl/ use strict; use warnings; # First, setting the directories we're interested in. my $inputs = "~/inputs"; # inputs we upload to the server. my $results = "~/results"; # results coming in. my @array; # tarballs of the incoming results. chomp (@array = system "ls $results\/*.tar.gz"); # putting all tar fil +es in an array # tar can't accept multiple tar.gz files as input # arguments after the tarball filename are expected to be files to unt +ar from the tarball. foreach (@array) { system "tar -tvf $results\/$_"; }

And this is the output I'm getting:

/home/user/results/results_back.tar.gz (my comment -> that's the ls c +ommand output, so it is finding one tar.gz file, I only have one for +now) tar: 0: Cannot open: No such file or directory tar: Error is not recoverable: exiting now

So there seems to be something wrong but I can't find what. As you can see, for now I'm only listing the tar.gz contents, if I get it working I'll add the real extract command.

Have I made a very obvious mistake? It would be great if you could give me a hint about what might be happening.

Thank you! :) I'd really appreciate any help :)


In reply to foreach loop to untar multiple files by fasoli

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.