Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 659617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:03:53+00:00 2026-05-13T23:03:53+00:00

I’m trying to write a Perl script that will parse the output of the

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:03:53+00:00Added an answer on May 13, 2026 at 11:03 pm

    The key is to parse one chunk at a time and match all the relevant stuff at once. See qr in perldoc perlop and $/ in perldoc perlvar.

    Keeping in mind the fact that you also wanted to put the information in a data structure that would allow you to query and manipulate the information, here is one final revision. The code below uses the ability of SQLite to create in-memory databases. You might actually want to split the functionality into two scripts: One to parse and store the data and another one to do whatever manipulation you need. In fact, it might be possible to do all necessary manipulation in SQL.

    #!/usr/bin/perl
    use v5.010;
    use strict; use warnings;
    use DBI;
    
    my $dbh = get_dbh();
    
    my $header_pattern = qr{
        History[ ]for:     [ ](?<filename>[^\n]+)         \n
        Description:       [ ](?<description>[^\n]+)      \n
        Locked[ ]by:       [ ]?(?<lockedby>[^\n]*)        \n
        Status:            [ ](?<status>.[^\n]+)          \n
    }x;
    
    my $revision_pattern = qr{-+\n
        Revision:          [ ](?<revision>\d+)           [ ]
        View:              [ ](?<view>.+)                [ ]
        Branch[ ]Revision: [ ](?<branch_revision>[^\n]+) \n
        Author:            [ ](?<author>.+)              [ ]
        Date:              [ ](?<revdate>[^\n]+)         \n
        (?<summary>.*)                                   \n
    }x;
    
    local $/ = '=' x 77 . "\n";
    
    while ( my $entry = <>) {
        if ( $entry =~ $header_pattern ) {
            my %file = %+;
            $dbh->do(sprintf(
                    q{INSERT INTO files (%s) VALUES (%s)},
                    join(',', keys %file), 
                    join(',', ('?') x keys %file),
                ), {}, values %file );
    
            while ( $entry =~ /$revision_pattern/g ) {
                my %rev = %+;
                $dbh->do(sprintf(
                        q{INSERT INTO revisions (%s) VALUES (%s)},
                        join(',', filename => keys %rev),
                        join(',', ('?') x (1 + keys %rev)),
                    ), {}, $file{filename}, values %rev );
            }
        }
    }
    
    my $revs = $dbh->selectall_arrayref(
        q{SELECT * FROM revisions JOIN files
        ON files.filename = revisions.filename},
        { Slice => {} }
    );
    
    use Data::Dumper;
    print Dumper $revs;
    
    sub get_dbh {
        my $dbh = DBI->connect(
            'dbi:SQLite:dbname=:memory:', undef, undef,
            { RaiseError => 1, AutoCommit => 1 }
        );
    
        $dbh->do(q{PRAGMA foreign_keys = ON});
        $dbh->do(q{CREATE TABLE files (
                filename    VARCHAR PRIMARY KEY,
                description VARCHAR,
                lockedby    VARCHAR,
                status      VARCHAR
        )});
        $dbh->do(q{CREATE TABLE revisions (
                filename        VARCHAR,
                revision        VARCHAR,
                view            VARCHAR,
                branch_revision VARCHAR,
                author          VARCHAR,
                revdate         VARCHAR,
                summary         VARCHAR,
                CONSTRAINT pk_revisions PRIMARY KEY (filename, revision),
                CONSTRAINT fk_revisions_files FOREIGN KEY (filename)
                REFERENCES files(filename)
        )});
    
        return $dbh;
    }
    

    Output:

    C:\Temp> y.pl test.txt
    $VAR1 = [
              {
                'status' => 'Current',
                'revdate' => '3/22/08 11:16:16 AM CST',
                'author' => 'John Smith',
                'description' => 'Some files',
                'revision' => '1',
                'filename' => 'main.h',
                'summary' => 'Main header',
                'view' => 'The View Name',
                'branch_revision' => '1.0',
                'lockedby' => ''
              },
              {
                'status' => 'Current',
                'revdate' => '3/22/08 1:55:55 PM CST',
                'author' => 'Jane Doe',
                'description' => 'Some files',
                'revision' => '2',
                'filename' => 'main.c',
                'summary' => 'Made an update.',
                'view' => 'The View Name',
                'branch_revision' => '1.1',
                'lockedby' => ''
              },
              {
                'status' => 'Current',
                'revdate' => '3/22/08 11:16:16 AM CST',
                'author' => 'John Smith',
                'description' => 'Some files',
                'revision' => '1',
                'filename' => 'main.c',
                'summary' => 'Initial revision',
                'view' => 'The View Name',
                'branch_revision' => '1.0',
                'lockedby' => ''
              }
            ];
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.