0

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 by reza.adinata: n/a

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by reza.adinata
0

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

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.