| Net-LDAP-LDAPhash documentation | Contained in the Net-LDAP-LDAPhash distribution. |
Net::LDAP::LDAPhash - Takes from a search and turns it into a hash.
Version 1.0.2
use Net::LDAP::LDAPhash;
my $ldapconnection = Net::LDAP->new( "127.0.0.1" )
my $bindMessage->bind( "cn=admin,dc=someBase", password=>"password", version=>3 );
my $mesg = $ldapconnection->search(scope=>"sub","dc=someBase", filter=>"(objectClass=*)");
my %foo = LDAPhash($mesg);
...
LDAPhash
This takes from a search and turns it into a hash.
The returned has is in the following format.
{DN}{ldap}{attribute}[array of values for this attribute]
The reason for the {ldap} is to allow for other values and the like to be tagged onto a hash for a DN that are unrelated to LDAP.
This function does not make any attempt to check if the search succedded or not.
Zane C. Bowers, <vvelox at vvelox.net>
Please report any bugs or the like to vvelox@vvelox.net.
You can find documentation for this module with the perldoc command.
perldoc Net::LDAP::LDAPhash
Copyright 2008 Zane C. Bowers, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Net-LDAP-LDAPhash documentation | Contained in the Net-LDAP-LDAPhash distribution. |
package Net::LDAP::LDAPhash; use warnings; use strict; use Net::LDAP; use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); our @ISA = qw(Exporter); our @EXPORT = qw(LDAPhash); our @EXPORT_OK = qw(LDAPhash); our %EXPORT_TAGS = (DEFAULT => [qw(LDAPhash)]);
our $VERSION = '1.0.2';
sub LDAPhash { my $mesg = $_[0]; #the object returned from a LDAP search #used for holding the data, before returning it my %data; #builds it my $entryinter=0; my $max = $mesg->count; for ( $entryinter = 0 ; $entryinter < $max ; $entryinter++ ){ my $entry = $mesg->entry ( $entryinter ); $data{$entry->dn}={ldap=>{dn=>$entry->dn},internal=>{changed=>0}}; #builds a hash of attributes foreach my $attr ( $entry->attributes ) { $data{$entry->dn}{ldap}{$attr}=[]; #builds the array of values for the attribute my $valueinter=0; my @attributes=$entry->get_value($attr); while (defined($attributes[$valueinter])){ $data{$entry->dn}{ldap}{$attr}[$valueinter]=$attributes[$valueinter]; $valueinter++; }; }; }; return %data; };
1; # End of Net::LDAP::LDAPhash