Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

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

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);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://2423]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-19 12:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found