Archive - Originally posted on "The Horse's Mouth" - 2008-07-14 08:14:15 - Graham Ellis
"There are six ways of doing anything in Perl." So say I on Perl courses and just occasionally I come up with an example that proves it. This one doesn't quite - I show you just five ways of finding the names of all the files in the current directory:
$stuff = `ls`;
@fings = glob("*");
opendir(DH,".");
@allfings = readdir(DH);
@another = <*>;
open (FH,"ls|");
@yetmore = <FH>;
Why so many different options? A good question, partly answered by the fact that they're all slightly different in what they do, so each has its ideal use. But I'll admit that the language probably didn't need THAT many ways all in quite common use. It does keep me on my toes on Perl Programming Courses such as the one I ran last week.