Now that I can pull the givenname and department, if I were to want to pull a list of "sn" in my search criteria(such as "smith, jones, peters"), the print statement which checks if the values are one of "surname or department" would continously print all values for "smith, jones, and peters".
I my case I would like to generate a list I can then be parsed pulling the "surname and deapartment" to do something with this.
For example:
currently it would print:
"SmithY100JonesZ300PetersXL200"
What I would like to be able to do is have an output like:
"SmithY100:JonesZ300:PetersXL200"
Being able to group the information for each name/department. I can throw this into a messy array, but I'm hoping there some suggestions I can learn from and do this more efficiently.
# configuration: Put the fields you want here.
my @fields_i_want_to_see= qw(givenname department);
my %show_field = map { $_ => 1 } @fields_i_want_to_see;
use Net::LDAP;
$ldap = Net::LDAP->new('ldap.acme.com') or die "$@";
$mesg = $ldap->search(
base => "o=acme.com",
scope => 'sub',
filter => "sn=smith",
);
#
# At this point the user can get the returned data
# as an array or as a stack.
# In this example we will use an array
# How many entries were returned from the search
my $max = $mesg->count;
for( my $index = 0 ; $index < $max ; $index++)
{
my $entry = $mesg->entry($index);
my $dn = $entry->dn; # Obtain DN of this entry
@attrs = $entry->attributes; # Obtain attributes for this entry.
foreach my $var (@attrs)
{
#get a list of values for a given attribute
$attr = $entry->get_value( $var, asref => 1 );
if ( defined($attr) )
{
foreach my $value ( @$attr )
{
# I'd like to be able to check when the we're past the last
+entry we're looking for, for each "smith, jones, and peters"
+
print "$var: $value\n" if $show_field{$var};# Print each val
+ue for the attribute.
}
}
+
}
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.