Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Think about Loose Coupling
 
PerlMonks  

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

by Elihu (Novice)
on Jan 25, 2000 at 02:21 UTC ( [id://2423]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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 17: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 14: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);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://2423]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.