I think this does what you want, except I've put in "<stuff>" where you had "$$"-- when I use Perl to tag text I tend to put in HTML or XML-like tags and then use an XML or HTML parser to extract a data structure to stick into a database or whatever.

open(MYINPUTFILE, "<sdnew02.txt"); while (<MYINPUTFILE>){ $_ =~ s/(\s-)$/$1\<stuff\>/; $_ =~ s/(:)$/$1\<stuff\>/; print $_,""; }

You seem to have gotten hung up on worrying about the returns or newlines, when you should have recognized that you needed the end of line anchor. If you want to make the replacement more robust you could put in some matches to arbitrary amounts of whitespace before and after the "-" or ":", but before the $ anchor.

From what you describe, Perl would probably do all the text munging you need. Databases are great for randomly accessing data based on whatever relationships you want to select on, but Perl is hard to beat for dismantling text. Most of what I use Perl for is taking apart text and sticking it into databases for other purposes. Friedl's book "Mastering Regular Expressions" is still a great place to start. There are probably free tutorials floating around the web, but MRE gives clear explanations and gets you up to speed fast.


In reply to Re^5: Reg Exp to handle variations in the matched pattern by bitingduck
in thread Reg Exp to handle variations in the matched pattern by markjrouse

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.