Monthly Archives: October 2009


find multiple values of text in a block of text :: perl

From time to time I’m asked to do an odd job here and there, so I have a whole bunch of little snippets of scripts that I have created for people, to make their jobs faster, easier and more efficient. This last one, I was pretty pleased with, as it is very dynamic in what it can do.
Basically, the requirements were very vague–

“We need to find a range of values in a block of text.
The block of text will sometimes be 2 lines, or can be up to 20 lines.
The files we are searching through are in all different formats.
We would like to do multiple searches in one action.
We need to search for multiple values in a search, and only pass if all values are found within the line count we specify.
We would like our search data to be in a separate file we can build and run the search against this.
We would like to have total control over what file to search through.
We need to know the line number it was found on, when it is found.
If possible, can we run this on a windows box, and on a mainframe server to which we can’t install apps”

So with all these in mind, I was off to write a script. I wanted to use ruby, but knew it wasn’t native to mainframe’s, so I opted for Perl instead. My Perl skills are not what I would like them to be, so feel free to update/criticise/chop my code :)
read more »