hello perl mongers,

i think this is more of a hashref or HoH question, I'm seeing a data structure similar to HoH in the data dumper output, but am having problems accessing key value pairs returned to the $hashref = Net::LDAP::LDIF->new function. specifically i'm having issues accessing the dn even though it's listed as a attribute in the ldif file. ldif data file example:
# extended LDIF # # LDAPv3 # base <ou=help,dc=perl,dc=monks> with scope subtree # filter: (|(Id1=*)(Id2=*)) # requesting: dn FriendlyId CreatedOn # # userid, help, perlmonks.com dn: uid=userid,ou=help,dc=perl,dc=monks FriendlyId: Pizza IdCreatedOn: 27-02-2099 00:00:00 data dumper displays the dn's in its output via data dumper: <code> $VAR1 = bless( { 'attrs' => { 'friendlyid' => [ 'Pizza' ], 'idcreatedon' => [ '27-02-2099 00:00 +:00' ] }, 'changes' => [], 'asn' => { 'objectName' => 'uid=userid,ou=help,dc=per +l,dc=monks',
What I'm interested in is the objectname above which happens to be the dn and holds the information i need to formulate my report, along with the other data in the object. my problem is that i can't access the dn object within each entry, but can access the other attributes available in the ldif. I see them in data dumper out put and can access them via standard methods. i.e. entry->get_value("attribute-name"), but this doesn't work for the dn...
#i.e. these work: print $entry->get_value("IdCreatedOn")."\n"; print $entry->get_value("FriendlyId")."\n"; #but can't get the dn: print $entry->get_value("dn")."\n"; print $entry->get_value("objectName")."\n";
above won't pull back the object name which has the dn i need to access and itterate through along with the other elements of the hash.
#!/usr/bin/perl use Net::LDAP::LDIF; use Net::LDAP::Entry; use Data::Dumper; use strict; use warnings; my $ldif = Net::LDAP::LDIF->new( "../packages/ldapsearch2.ldif", "r") +or die "file not exits\n"; while( not $ldif->eof ( ) ) { my $entry = $ldif->read_entry ( ); #this doesn't work print "HERE is the DN!!!"."\n"; # 'asn' => { # 'objectName' print "anything?" . "\n". $ldif->{'asn'}{'objectName'}. "\n"; # but this shows the dn's in the output, but how do I get them +to print? print Dumper $entry; } #the following doesn't work.. my @arrayOfDNs = keys %$ldif; print "here are all the dn's:"."\n"; print @arrayOfDNs;
looking for some jedi ldif reporting experts, I know you're out there!! ...and probably can solve this very quickly, THANK YOU!.
Really could use the help here, working to automate this ldif export perl to csv daily processing and i know i can always count on the monks to point me in the right direction, thanks in advance. this returns the keys, just need to get the subkeys
foreach my $key (keys %{$ldif}) { print "\n this is the key:" . $key . "\n"; #need to dereference the subkeys... not working yet below. #for my $subkey ( keys %{$ldif{$key}} ) { # print "Subkey=$$ldif{$key}{$subkey} "; #} print "\n" . "\n"; }
- 3dbc

In reply to can't access dn within ldif file by 3dbc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.