Hi all,
I need a perl script that can open files (given in command line arguments) and extract/print out any dates or times found in it. The format of the dates and times can be any reasonable format.
The problem I have is I don't know how to print out the matching part of the file once i find it. Any ideas?
-Skyrim
Let's start by assuming all dates will look like 'mm/dd/yyyy' and all times will look like 'hh:mm'. You need to express these two patterns as regular expressions, aka regexes. Hopefully, no date or time will extend beyond one record so you can read each file one line at a time. (Otherwise you would have to 'slurp' each input file so the entire file goes into a scalar variable.) Look for matches in each input record you read from your file(s) in such a way as to capture the matching portions into variables which you can print. Easier said than done, right? But once you have a script that does this, and you need to find all the other reasonable formats that dates and times could have in the file you will be reading, you will simply create and incorporate additional regex patterns into your script.