These look like fixed-width records to me. That's a job for unpack.

Something like this would tell lines that start a new record apart from those which don't:

while(<>) { chomp; my ( $cnum, $details ) = unpack "x a5 x a*", $_; if( $cnum =~ /\d/ ) { # new record } else { # follow-up line } }
The string left in $details for follow-up lines seem to roughly conform to the unpack format
a4 x a4 x a5 x2 a3 x3 a3 x2 a18 x a3 x a3 x a
Something similar would have to be devised for the $details in record-starting lines. Also, the else-branch will need to test $details against /^\*\*/ to tell apart lines with course details from those with constraints. You'll need a few variables to store some state when you detect a new record, so you can access it in the following iterations on the detail lines. The logic is simple enough that you need not and should not use gotos.

Makeshifts last the longest.


In reply to Re: Parsing COD text help by Aristotle
in thread Parsing COD text help by dimmesdale

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.