in reply to Re^2: Perl File Manipulation
in thread Perl File Manipulation

Thanks for the fix (and the test).
I'm not familiar with the 'LDAP Data Interchange Format' (to say the least) but is 'uid' always bound to follow 'cn'?

I don't know either, but if it varies, reading the data one whole record at a time will make it a lot easier to handle the variation.

Replies are listed 'Best First'.
Re^4: Perl File Manipulation
by topperge (Initiate) on Jul 11, 2004 at 17:44 UTC
    Hey guys,
    Thanks for all the help, I've almost got it working now. UID is not a necessary attribute of an LDAP record, however to use Oracle Portal it is. I'm trying to move from a Oracles 902 ldap directory to a 10g directory and this is my final step.

    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. i.e.

    cn=HELPDESK,cn=users,dc=myco,dc=com
    orclactivestartdate: 20031202043257Z
    objectclass: top
    objectclass: person
    objectclass: inetOrgPerson
    objectclass: organizationalPerson
    objectclass: orclUser
    objectclass: orclUserV2
    o: MyOrg
    orcldefaultprofilegroup: cn=user_grp,cn=portal_groups,cn=groups,dc=myco,dc=com
    givenname: Joe
    sn: Schmo
    telephonenumber: 800-999-9999
    userpassword: {MD4}1a4QEWWP+nCZ19uAy9w==
    mail: joe_blow@myco.com
    cn: HELPDESK
    Any ideas? Thanks again Matt
      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.