http://www.perlmonks.org?node_id=2423

Elihu has asked for the wisdom of the Perl Monks concerning the following question:

I was trying to write a simple perl script the other day that, when given a tar or tar.gz file, got a listing of its contents (tar -tf or tar -tzf), put that into an array, then unlinked all those files. I often get tarballs that dump into the current directory, then have to manually delete all the files. I've written the script to take a file where I redirected the output of the tar listing, and removes files from the 2nd file, but I'd like to just dump all the files from the tarball into an array, and operate off of that.

Originally posted as a Categorized Question.

  • Comment on How do I store and manipulate the output from another process?

Replies are listed 'Best First'.
Re: How do I store and manipulate the output from another process?
by vroom (His Eminence) on Jan 25, 2000 at 22:00 UTC
    Your best choices for collecting output from a program are using backticks `` or the open call.
    $output=`tar -tf`; #collects all the output from the "tar -tf" comman +d open TAR, "tar -tf|"; #open a process with a pipe on the right side while(<TAR>){ #get the output line by line into $_; do_something($_); #process the results; } close TAR;
Re: How do I store and manipulate the output from another process?
by draconis (Scribe) on Apr 29, 2003 at 18:01 UTC
    Another method would be to use qx(). qx() is a genralized form of using backticks - and is does interpolation as well.
    $output=qx(tar -tf);