my name is luis, live in arg.
i have a problem, which can not solve.
**IN BASH**
pwd
/home/labs-perl
ls
file1.pl file2.pl
**IN PERL**
my $ls = exec("ls");
my @lsarray = split(/\s+/, $ls);
print "$lsarray[1]\n"; #how this, i need the solution. >> file.pl
file1.pl file2.pl # but this is see in shell.
The output you see is not from the print statement, it is the console output of
ls. To get thelsoutput into a variable, use backticks:This is because
execdoes not return, the statements after it are not executed. From perldoc:But using
systemcommand will not help you as it does not allow output capturing, hence, the backticks. However, usingglobfunctions is better:Also, perl array indices start at 0, not 1. To get file1.pl you should use
print "$lsarray[0]\n".