Originally Posted by grail
Would not the best option be to simply extend the perl script to cope with the new requirement?
Depends on how you define 'best', I suppose. My logic is that when a tool that does something very well already exits, I want to use that. In this case, that tool is find
. Using the existing perl script also adheres to this principle. It is known to do one thing well, so use it that way, and build around it.
demonstrates the power of find
very nicely, and also demonstrates and explains a well structured way to approach the problem: iteration over a file set, especially with recursion, suggests using find
. The output of find
is a list, which feeds the while
loop, so there is the iteration part of the problem solved. Once that part of the problem is addressed, he assembles a couple of key variables that are the arguments to the perl script. Finally, that last thing in each iteration is to invoke the perl script with arguments that are variables with nice human-readable names.
There is more to learn from Nominal's code than just how to solve the problem. It is a good demonstration of how structure the solution.