On 11-04-05 09:24 AM, ANJAN PURKAYASTHA wrote:
Hi,
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 could use open:

#!/usr/bin/env perl

use strict;
use warnings;

open my $ls_fh, '-|', 'ls' or die "could not open `ls`: $!\n";
chomp( my @files = <$ls_fh> );
close $ls_fh or die "could not open `ls`: $!\n";

print "@files\n";
__END__


--
Just my 0.00000002 million dollars worth,
  Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software:  Fail early & often.

Eliminate software piracy:  use only FLOSS.

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