⭐ in reply to How do I read all the file names of a directory into an array?
Use the directory functions: opendir, closedir and readdir.
opendir DIR, $dir or die "cannot open dir $dir: $!"; my @file= readdir DIR; closedir DIR;
This will neatly put the list of file names in the @file array (with no \n at the end of each file name).
There is a couple of other things you can improve in your code BTW:
Finally I have no idea why $filename$i =~ s/\*//g; is there? Is there a chance you that you might find a '*' in filenames?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Answer: How do I read all the file names of a directory into an array?
by Ri-Del (Friar) on Dec 10, 2000 at 19:47 UTC | |
by chipmunk (Parson) on Dec 11, 2000 at 01:55 UTC | |
by duct_tape (Hermit) on Dec 10, 2000 at 20:45 UTC |