|Perl Monk, Perl Meditation|
Text File Section Extractorby BJ_Covert_Action (Beadle)
|on Apr 09, 2009 at 21:55 UTC||Need Help??|
I've spent the last couple hours developing a small utility for my personal use at home and work. Basically, it is program that asks for a file to read from, a file to write to, and two strings containing patterns. Optionally, the file to be read can be taken as the first command line argument while the file to output to can be taken as the second command line argument. If only one argument is given, it is assumed to be the input file.
Anyways, the program calls a subroutine called pry to move through the input file (file to be read) line by line. It looks for the first pattern specified, and, upon finding it, prints each consecutive line to the output file specified until the second pattern is found.
I intend to upgrade and tweak on this utility as life goes on, but for now it's a decent, bare-bones utility. I am probably going to add the option to add case insensitivity to the start and stop patterns, as well as the option to specify how many sections within a text file the program should extract (for instance, if it should match all groups that it finds, or just some, or just the first, or last, and so on.
I am probably also going to try to turn it into a module as well so that I can just load it into my other programs and pry chunks out of text files as I see fit. Of course, I don't know much about module development yet (only on chapter 7 of the camel book and chapter 7 of Simon Cozens book), so that is for a later time.
I imagine someone probably already has a whole package and/or utility that does this or something similar already. It is probably a lot more professional looking as well. Nonetheless, this is a fun little program I wrote just to see if I could, and to test my skills thus far. If anyone else could/would find it useful, I want them to have access to it as well. I welcome any and all criticisms and thoughts.
Without further ado, I give you the PINSS (PINSS Is Not a Sentient Searcher) program.