in reply to Reading a directory into an array using <>

If the string(sic --> should be 'thing') inside the angle brackets is anything other than a filehandle name or a scalar variable (even if there are just extra spaces), it is interpreted as a filename pattern to be 'globbed'. (Programmig Perl, p. 83)

You have a scalar variable inside the angle brackets, so it is *not* interpreted as a filename pattern to be globbed.

You could trick perl like this:

my @fnames = <${path}>

But since the angle operator calls glob() implicitly when you don't provide it with a file handle or scalar variable inside the brackets, you might as well just call glob() explicitly yourself. Note that the argument to glob() is a string, so you need quotes.

You can also use opendir() and readdir():

use strict; use warnings; use 5.010; my $path = '/var/log'; opendir(my $TARGET_DIR, $path) or die "Couldn't open directory $path: $!"; my @all_files = readdir $TARGET_DIR; closedir $TARGET_DIR;

There are a couple of differences, though: 1) glob() will ignore invisible files, 2) glob() tacks the file name onto the specified path, where readdir() just returns the filenames.