Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Net::LDAP::LDIF

by bronto (Priest)
on Apr 28, 2004 at 14:07 UTC ( [id://348829]=note: print w/replies, xml ) Need Help??


in reply to Net::LDAP::LDIF

Well... you have a bunch of Net::LDAP::Entry objects and you write them down in LDIF format using write_entry...

What do you want to be explained?

Anyway, a snippet of code I wrote in 5 minutes

#!/usr/bin/perl + use strict ; use warnings ; + use Net::LDAP ; use Net::LDAP::LDIF ; + my $ldap = Net::LDAP->new('10.39.0.208',port => 3268) ; die unless defined $ldap ; + $ldap->bind('a_dn_of_mine', password => 'a_password_of_mine') or die ; + my $res = $ldap->search(base => 'dc=tiscali,dc=com', filter => '(givenName=Marco)') ; + die $res->code if $res->is_error ; + my $ldif = Net::LDAP::LDIF->new('myself.ldif','w') ; die unless defined $ldif ; + $ldif->write_entry($res->entries) ; + $ldif->done ; $ldap->unbind ;

I hope it helps

Ciao!
--bronto


The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
--John M. Dlugosz

Replies are listed 'Best First'.
Re: Re: Net::LDAP::LDIF
by nqklooless (Initiate) on Apr 28, 2004 at 17:00 UTC
    It worked! So easy! Thanks.
Re: Re: Net::LDAP::LDIF
by nqklooless (Initiate) on Apr 28, 2004 at 15:08 UTC
    Thanks. What I don't get is how to get the output from read-entry to be written by write-entry.

      Well, man says:

      read_entry ( ) Read one entry from the file and return it as a "Net::LDAP: +:Entry" object.

      So you read entries from an LDIF file, one by one, and then you write them on another, that's all. What you need to change in the script I already posted is:

      • read the entries one by one from an LDIF file (not from an LDAP server, and you don't have an entries method that returns the entries all-in-a-sweep) into a variable, say $e
      • write the ones you want on the other file, using $ldif->write_entry($e)

      Since you say that you know how to use read_entry, you should be able to modify my script any way you like to do the job.

      Ciao!
      --bronto


      The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
      --John M. Dlugosz

Log In?
Username:
Password:

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

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

    No recent polls found