I'm trying to write a Perl script that will parse the output of the stcmd.exe (the StarTeam command line client) hist command. I'm getting the history for every file in a view and the output looks something like this:
Folder: The View Name (working dir: C:\Projects\dir) History for: main.h Description: Some files Locked by: Status: Current ---------------------------- Revision: 1 View: The View Name Branch Revision: 1.0 Author: John Smith Date: 3/22/08 11:16:16 AM CST Main header ============================================================================= History for: main.c Description: Some files Locked by: Status: Current ---------------------------- Revision: 2 View: The View Name Branch Revision: 1.1 Author: Jane Doe Date: 3/22/08 1:55:55 PM CST Made an update. ---------------------------- Revision: 1 View: The View Name Branch Revision: 1.0 Author: John Smith Date: 3/22/08 11:16:16 AM CST Initial revision =============================================================================
Note that the revision summary can contain newlines and can be blank (in which case there's no line for it at all).
I want to get the filename and, for each revision, the author name (first and last), date, and change summary. I'd like to place this information in a data structure where I can sort revisions by date and combine revisions if the date, author, and summary match up. (I think I can figure this part out if someone can help me with the parsing.) I'm not great with regular expressions or Perl, but here's what I'm trying to work with right now:
# $hist contains the stcmd output in the format above
while($hist =~ /History for: (?<filename>.)/s)
{
# Record filename somewhere with $+{filename}
while($hist =~ /^Revision: (?<file_rev>\S+) View: (?<view_name>.+) Branch Revision: (?<branch_rev>\S+).\nAuthor: (?<author>.*) Date: (?<date>.*) \w+\r\n(?<summary>.*)/)
{
# Extract things with $+{author}, $+{date}, $+{summary}
}
}
This doesn't work, however. For all I know I may be approaching it completely wrong. Can someone point me in the right direction?