Hi all,

I am trying to make an array of folders and want to basically take all files inside the folder. However, I got an error saying "missing a $ loop variable". I have add a $, and worked around with this codes, but still did not work .. Is it possible to get all files inside an array of folder?

my $folder="1";
my $folder2="2";
my @fld = ($folder, $folder2);
for each (@fld)
{
opendir(FOLD, @fld);
my @FD = readdir(FOLD);
// I want to read all values inside each directories and display it. how to achieve this?
}

Thank you for the guidance

Edited 6 Years Ago by reza.adinata: n/a

I just found another syntax error, which should be

foreach $fld (@fld)
{
opendir(FOLD, @fld);
my @FD = readdir(FOLD);
// I want to read all values inside each directories and display it. how to achieve this?
}

but still I don't know how to fix this display all files inside the folder arrays. it shows different errors which are : "readdir() attempted on invalid dirhandle FOLD"

Thank you for the guidance

opendir(FOLD, @fld); First error I see is that opendir expects an expression naming one directory. Any variable starting with @ contains an array whereas opendir needs a string representing the name of one directory only.

This question has already been answered. Start a new discussion instead.