Storing the Linux command output to an array in perl script

Hi

I am trying to store the output of a command into an array in perl script.

I am able to store but the problem is i am unable to print the array line with one line space. i mean i inserted the \n in loop ...but not getting the result.

I have written like this

#!/usr/bin/perl
@a = system ("ls -l");
chomp @a;
foreach $i (@a) {
        print "$i\n\n";
}
exit(0);

After the ls -l output only i m getting 2 line space ...i need spcae between every line in the array ...

Pls suggest me

Hi,
system return status of command in parameter, for your problem, you can do it as:

#!/usr/bin/perl
@a = `ls -l`;
chomp @a;
foreach $i (@a) {
print "$i\n\n";
}
exit(0);

another way ..

#!/usr/bin/perl
open(LS,"ls -l |") or die "$!\n";
while (<LS>){
print $_,"\n";
}
exit(0);