in reply to Re: foreach loop to untar multiple files
in thread foreach loop to untar multiple files

Carefully look at your output... the file path is being specified twice... tar: /home/user/results//home/user/results/results_back.tar.gz. Try this:

for (@tar){ print `tar -tvf $_`; }

ps. I'd recommend you look at my Archive::Extract example here, to avoid having to shell out.

Replies are listed 'Best First'.
Re^3: foreach loop to untar multiple files
by afoken (Chancellor) on Nov 13, 2015 at 17:59 UTC
    for (@tar){ print `tar -tvf $_`; }

    Quite dangerous. Imaginge a file named "foo ; rm -rf * ; bar.tar.gz", injected into @tar by ls or glob. (And yes, that's a legal filename.)

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re^3: foreach loop to untar multiple files
by fasoli (Beadle) on Nov 13, 2015 at 17:22 UTC

    Thanks for your answer. I noticed that the file path is specified twice, that's why I said that I tried to delete $results and only go for $_. However this was obviously wrong as it hangs for a few seconds and fails quietly and I was wondering if anybody knew why. The same happens with the script you provided :(

    I will look at the Extract example in more detail, it just scared me a bit as it looked a little more complicated.

      My example *should* be good to go, just update the path info in the variables. If you try it and you have issues, reply back and we'll help you through it :)