ffind.pl – My first Object Oriented Perl Script using Moose February 20th, 2013
As you can see from my earlier posts I got over the last couple of month a little bit in contact with Perl as a script language being used as a substitution for the old Dos-/Windows batch processor for some general script based tasks and in special for creating an automatic and full customizable build system for a larger Visual C++ project with a bunch of targets and some resulting distribution packages (installers and zip-archives).
For practicing purposes I invested a bit time in investigating about the OOP-features of Perl. When you read about it in the internet a lot of people share the opinion that Perl’s default OOP-support works well, but it requires a lot of tedious work for the programmer to set up a class. They recommend you to give Moose a try, which is a relatively new module of Perl. It promises to make OOP under Perl easy and is already deployed in production by some real companies.
To learn Moose by doing I decided to program a little script which mimics in a smaller feature subset the possibilities of the UNIX console program “find” as I know it from my earlier days. It should give me under Windows (and of course under other OSes where Perl is available too) the possibility to do a recursive file search using some include- and exclude-filters and let on the result set happen some actions like “print”, “put to an archive” or “clean the matching” files.
The resulting script has the name ffind.pl (file find). Here are some examples for using it on the Windows command line:
1 2 3 4 5 6 7 8 9 10 11
REM Match in users temp dir all items whose name contains REM substring ‘pic’ except the gifs and jpgs: perl ffind.pl C:\Users\daniel\Temp -ni "*pic*" -ne "*.gif,*.png" REM Create a zip-archive of all text files w. automatic current REM timestamp name in dir ‘c:\users\daniel\backups’: perl ffind.pl ./ -ni “*.txt” –zip “c:\users\daniel\backups” REM Delete / clean all object files. Don’t display file deletion REM warning / confirmation: perl ffind.pl ./ -ni “*.o,*.obj” -fclean
View / download the files and the final conclusion:
I wrote a little blog post report about the implementation of ffind.pl as a pdf. The addressed topics can best be described by the following tags:
- Software Tests
- Command line Parsing
You can view/download it here plus the script (of course) and a little directory tree of empty files and folders for testing the script:
- ffind_article.pdf: The blog post report
- ffind-1.1.pl: The script
- test-dir-tree-ffind.zip: A directory tree of empty files and folders for testing the script
My final conclusion about Moose & Perl:
Finally it’s a nice addition to Perl to have the possibility to leverage now the powers of OOP more easily once you have managed to overcome the first obstacles of Moose. In detail if you have made a mistake it’s not easy to get known from the error message the real cause of the error. But so far I guess that’s more a general problem of Perl, not Moose 😉 So if you have the choice you might want to give Python a try as it is object oriented by design and a lot easier to learn without being less powerful than Perl.
This entry was posted on Wednesday, February 20th, 2013 at 18:50 and is filed under C++ (and more...). You can follow any responses to this entry through the RSS 2.0 feed.You can leave a response, or trackback from your own site.