My only problem now is I have 4 records with cn on the last line of the record and for some reason its not find it in the search.

If you're using the code that I originally proposed, then the match is failing because there is nothing that matches the "$3" ("$nexttag") portion of the regex. If you make that part of the match optional, it should work fine -- just put a "?" quantifier on the part that would be $3:

if ( /(\ncn: (\S+))\n(\S+)?/ ) {
Now, if you need to make sure that all the lines are in a specific order (e.g., if the "cn:/uid:" pair should not be the last two lines of the record), you would probably be best off splitting the record on "\n" (after you've fixed the uid line), assigning the lines to an array (or better yet, a hash, keyed by the first field on each line), and then printing the lines out in the desired order.

In reply to Re^5: Perl File Manipulation by graff
in thread Perl File Manipulation by topperge

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.