http://qs321.pair.com?node_id=707248


in reply to Re: greater efficiency required (ls, glob, or readdir?)
in thread greater efficiency required (ls, glob, or readdir?)

My personal opinion is that running a child process to get a directory listing is a rather silly thing to do. I wouldn't use ls. Doubly so for using cat for reading a file!!!

I second that; especially because $dir and $_ will be interpreted by the shell. So you will get problems if a directory name or entry has special characters in it.

Even if you don't think that this is important in your case, it's better to make the code more maintainable and re-usable for security-aware scenarios.

While you can avoid these problems by using open my $pipe, '-|', 'ls', $dir, it's really not worth the trouble; readdir (or IO::Dir) has less problems. And for reading the file, use open or File::Slurp.