[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: [ldap] ldif question



At 11:13 AM 2/4/99 -0700, Allen Reese wrote:
>Perl would help a lot if the entries are not in order.  there is a
>Perl-LDIF module, you could use that.
>
>One way using perl is:
>
>read the all the entries of the first LDIF file into a hash, %orig_entries
>then read the entries of the second into %new_entries.
>then cycle through the contents of new_entries, searching for each entry
>in orig_entries and putting the entry into @diff_entries if the entry
>doesn't exist in orig_entries or has changed.
>then you add all the entries in @diff_entries and %orig_entries together
>and write the new LDIF file.
>
>hope that helps.
>
>Allen Reese
>Senior Software Engineer
>Driversoft, Inc.
>allen@driversoft.com

I've done that. works slick. I use this (doesn't handle ::, multivalued
attributes or continuations, left as an exercise for the reader)...

$/ = "\n\n";
while (my $l = <>) {
 my %l = (
  'userpassword' => '', 'passwordlastupdated' => '', 'ssn' => '', 'uid' => ''
 );
 foreach my $ll (split (/\n/, $l)) {
  if ($ll =~ /^(\w+):\s*(.*)$/) {
   my ($a, $v) = ($1, $2);
   $l{$a} = $v;
  } else {
   die "Hey! Don't recognize $ll\n";
  }
 }
 # do stuff with %l here
}

-
Douglas E. Wegscheid
working for, but not expressing the position of, Whirlpool Corporation
wegscd@whirlpool.com
-
A wrong note played hesitatingly is a wrong note. A wrong note played with
conviction is interpretation.