perlquestion
fasoli
<p>Hello wise monks,</p>
<p>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 </p>
<code>#/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 files in an array
# tar can't accept multiple tar.gz files as input
# arguments after the tarball filename are expected to be files to untar from the tarball.
foreach (@array) {
system "tar -tvf $results\/$_";
}</code>
<p>And this is the output I'm getting:</p>
<code>/home/user/results/results_back.tar.gz (my comment -> that's the ls command 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</code>
<p>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.</p>
<p>Have I made a very obvious mistake? It would be great if you could give me a hint about what might be happening.</p>
<p>Thank you! :) I'd really appreciate any help :) </p>