Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Parsing of LDAP entry

by mariusz (Initiate)
on Jul 30, 2013 at 20:48 UTC ( [id://1047120]=perlquestion: print w/replies, xml ) Need Help??

mariusz has asked for the wisdom of the Perl Monks concerning the following question:

Gents,

I have one problem with Perl, so I would appreciate if you could help to find the best solution for that.

In my company we use SunOne LDAP. I want to connect to cn=changelog and read all entries in this node.

Structure of one entry looks like that:

dn: changeNumber=123,cn=changelog objectClass: top objectClass: changelogentry ...something not important.... changes: BASE64_TEXT

When I try to read ($entry->get_value("changes")) and decode changes, then I received something like this:

replace: A A: new_value - add: NEW_VAR NEW_VAR: ABC - delete: ABC - replace: history history: 1 history: 2 history: 3 -

In my case on the output I want to get (single line):

ADD: NEW_VAR=ABC|REPLACE: A=NEW_VALUE, HISTORY=1,2,3|DELETE: ABC.

Is there any simple way to "PARSE" changes value? Unfortunately, type of this value is string..

Replies are listed 'Best First'.
Re: Parsing of LDAP entry (get_value( $var, asref => 1 );
by Anonymous Monk on Jul 30, 2013 at 22:30 UTC

      Thank you for reply.

      Please take a look for my example:

      (...) my $ref = $entry->get_value ( 'changes', asref => 1 ); print Dumper($ref);

      Execution:

      perl test.pl $VAR1 = [ 'delete: employeeType employeeType: Intern - add: employeeType employeeType: No Longer Employed - add: description description: On 30-07-2013 05:17 removed from source. - add: nsAccountLock nsAccountLock: true - replace: modifiersname modifiersname: cn=mmariusz,ou=people,ou=testENV - replace: modifytimestamp modifytimestamp: 20130730031746Z - '

      So, this is stil "multiline" result in one variable. Probably I need to create some kind of function/object and make a parser for that:

      function magic() { my $string = shift; # some magic should be placed here :) #sample return return @replaced_attrs,@added_attrs,@delete_attrs; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1047120]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-03-19 04:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found