Temporarily, I am working on different code to achieve the same result. So I may better understand Perl, I submit the following code, albeit not working. I gratefully await your expertise on why it does not work. Grateful for your expertise. This code erractically outputs to OUT. Where should chomp; go in this example? Both PERSON and MGR have an equal number of lines. The desired result is:

line1 from PERSON changetype: modify replace: manager line1 from MGR line2 from PERSON changetype: modify replace: manager line2 from MGR ...etc... #! perl -slw use strict; use warnings; use diagnostics; use constant batchdir => "c:\temp10"; open (PERSON,"f1"); open (MGR,"f2"); open OUT, ">", "buildAD.ldif" or die "Cannot write to 'buildAD.ldif': +$!"; truncate (OUT, 0); my $line; my $line2; while ($line = <PERSON>) { #chomp; my @dn1 = split(/\s+/,$line); my $count = scalar(@dn1); print OUT "$line"; print OUT "changetype: modify"; print OUT "replace: manager"; while ($line2 = <MGR>) { #chomp; my @dn2 = split(/\s+/,$line2); my $count2 = scalar(@dn2); print OUT $line2, "\n", if ($count == $count2); } } close PERSON; close MGR; close OUT; exit;

Example data in OUT is here, the extra newline on line 2 should not be there, and all the numbers after 2821 are from <MGR>.

0104 changetype: modify replace: manager 2821 3682 1129 2050 4054 0755

In reply to Re^8: Perl Builds an LDIF by rfransix
in thread Perl Builds an LDIF by rfransix

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.