How can I read a directory in Perl with one statement?
directory, perl
Solution
Most elegant is to use a function someone else has already written.
use File::Slurp;
@files = read_dir $dir; # . and .. are removed by default
Problem
I'm writing a script that looks for certain files in a directory and processes them. I keep on writing the following: ``` opendir DIR, $dir; @files = readdir DIR; closedir DIR; ``` While I could (and in fact should) wrap this in a function, I was wondering if there's a more elegant way to do this?