B
Bucco
I am trying to put together a simple script that will parse a text file
that contains a list of tasks. Each line could be different in format
from the other. Most lines have words that are marked and can be
pulled out with a regex. Here is a simple example:
(A) @home Mow lawn d:6/30/06
@phone call home
(B) program @pc @desk Add text parser to the program
Basically, each line is a task in a list of todos. They can have one
of three priority rankings (A), (B), or (C). The priority is always
first on the line if it is present. Then There can be a project name
that the task is related to, "program". The next item on the line is
a context and starts with the @ symbol. Each task can have more than
one context. After this is the task description that consists of one
or more words and has no definitive marker. Some tasks may have a due
date after the task that is marked by a d: followed by a date.
So basically, the program will read in the text file, process each line
so that a task is printed to a new file in either a prject file, due
file, and/or context file. When processing each line, I thought of
breaking them down by white space into an array and then using a regex
to match the easy items and remove them the array and use them as a
hash key for the task.
I gues the best way might be to extract each marker assin it to a hash
as a key and then extract the task and assign it to the hash as the
value. I can't seem to get to this point without a lot of if
statements. I was wondering if anyone else had a cleaner way of doing
this.
Thanks
SA
that contains a list of tasks. Each line could be different in format
from the other. Most lines have words that are marked and can be
pulled out with a regex. Here is a simple example:
(A) @home Mow lawn d:6/30/06
@phone call home
(B) program @pc @desk Add text parser to the program
Basically, each line is a task in a list of todos. They can have one
of three priority rankings (A), (B), or (C). The priority is always
first on the line if it is present. Then There can be a project name
that the task is related to, "program". The next item on the line is
a context and starts with the @ symbol. Each task can have more than
one context. After this is the task description that consists of one
or more words and has no definitive marker. Some tasks may have a due
date after the task that is marked by a d: followed by a date.
So basically, the program will read in the text file, process each line
so that a task is printed to a new file in either a prject file, due
file, and/or context file. When processing each line, I thought of
breaking them down by white space into an array and then using a regex
to match the easy items and remove them the array and use them as a
hash key for the task.
I gues the best way might be to extract each marker assin it to a hash
as a key and then extract the task and assign it to the hash as the
value. I can't seem to get to this point without a lot of if
statements. I was wondering if anyone else had a cleaner way of doing
this.
Thanks
SA