title: Unable to process a perl LDAP search
body: <p>This is my first question on StackOverFlow so please let me know if I have done something wrong. </p>
  
  <p>I am writing a perl script to perform an LDAP search to identify the list groups that a user is a member of. I read the perldocs on the subject and found a few examples on this website but I have been unable to get the script to run properly.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>#!/usr/bin/perl
  
  use strict;
  use warnings;
  use Net::LDAP;
  
  my $ldap;
  my $ldapuser = "MVS\\user";
  my $ldappass = "passw0rd";
  my $searchbase = "DC=dom,DC=site,DC=labs,DC=domain,DC=net";
  my $attrs = "sAMAccountName, sn, givenname, memberOf";
  my $filter="(samAccountName=user)";
  my $result;
  
  # ensure the ldap connection is made
  print "Connecting to LDAP...\n";
  $_ = $ldap = Net::LDAP-&gt;new('dc1.mvs.cso.labs.rim.net')     or die "$@";
  
  # ensure the bind is successful
  print 'Binding....';
  $_ = $ldap-&gt;bind ("$ldapuser", password=&gt;$ldappass, version=&gt;3);
  print $_-&gt;error_text();
  
  
  $result = $ldap-&gt;search(base=&gt;"$searchbase", filter=&gt;"$filter", attrs=&gt;[$attrs]);
  
  my $max;
  my $i;
  my $entry;
  my $first;
  my $last;
  my $login;
  my @memberOf;
  
  $max = $result-&gt;count;
  print "Count: $max\n";
  
  for ($i=0;$i&lt;$max;$i++) {
  $entry = $result-&gt;entry($i);
  $last = $entry-&gt;get_value('sn');
  $login = $entry-&gt;get_value('sAMAccountName');
  @memberOf = $entry-&gt;get_value('memberOf');
  
  print "$first $last\n";
  print "$login\n";
  print "@memberOf\n";
  
  }
  $ldap-&gt;unbind;
  $ldap-&gt;disconnect;
  </code></pre>
  
  <p>Here is the result when I run this code:</p>
  
  <pre><code>Connecting to LDAP...
  
  Binding....Operation completed without error
  Count: 1
  Use of uninitialized value $first in concatenation (.) or string at ./ldap_test.cgi line 43, &lt;DATA&gt; line 604.
  Use of uninitialized value $last in concatenation (.) or string at ./ldap_test.cgi line 43, &lt;DATA&gt; line 604.
  Use of uninitialized value $login in concatenation (.) or string at ./ldap_test.cgi line 44, &lt;DATA&gt; line 604.
  </code></pre>
  
  <p>From what I can tell it seems to me that $entry is not getting any value returned when I run: </p>
  
  <pre><code>$entry = $result-&gt;entry($i);
  </code></pre>
  
  <p>but I could be wrong.
  Any help would be appreciated.</p>
  
  <p>Thanks,</p>