There is usually more than one way of doing things, and one should choose the one that gets the job done easiest without compromising security. :)
If Larry didn't want us to use system() he wouldn't have given it to us...
Your way of doing it does indeed seem more appropriate for that particular job, however, there are a few things to think about:
- That call may not be cross-platform if the program should be run somewhere else. On some platforms it may even give errors, while perls built-in functions should just return quietly on unsupported platforms.
- Make sure noone can put something into $dir from an external source. It is all too easy to execute arbitrary command this way. Don't let it happen to you. :)
So, in conclusion: the built-in functions has a lot of benefits to them, is the benefit of writing a little less code really bigger? I'm not so sure... A fast opendir, readdir, closedir really isn't that bad, is it? :)
You have moved into a dark place.
It is pitch black. You are likely to be eaten by a grue.