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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |