On 05/04/2011 14:24, ANJAN PURKAYASTHA wrote:

Is there any way to run a shell command from within a perl script and
capture the output in, say, an array?
One can run a shell command through the system function. But system itself
just returns a status code.

You should read the section on qx/STRING/ in perldoc perlop. Backticks
`` are the same as qx//, but I prefer the latter as it is more visible,
and backticks are liable to be confused with single quotes ''.

If you use qx// in scalar context it will return everything the command
sends to stdout in a single string. If you put it in list context it
will return a list of lines, each terminated by the current records
separator - probably "\n".

HTH,

Rob


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to