![]() |
|
Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Why I hate File::Find and how I (hope I) fixed itby mirod (Canon) |
on Aug 30, 2001 at 17:19 UTC ( #109068=perlmeditation: print w/replies, xml ) | Need Help?? |
OK, so every time someone here asks how to walk a directory tree and process files we all religiously (!) chant the File::Find mantra. The truth is that I have always hated File::Find. It just feels old. My main gripe is that the wanted function, which is called for each file found, does not accept arguments. So if I really need arguments, which happens quite often, then I have to use good ole globals. This is definitely _not_ what I'd call good coding practice. Plus how do I put this code in a module? So here is my solution, using closures to generate various functions from a single "template" one. The interesting part is really the make_wanted function, that takes a code reference and a list of arguments, and generates a function (with takes no arguments) that will call the code reference with the arguments (which will have the value they had when make_wanted was called):
Back to
Meditations
|
|