title: How to read the contents of a variable with Netldap
body: <p>I'm writing a script that receives as a parameter the name of a user and performs a search in LDAP but I can't find a way to use a Perl variable in the LDAP search filter.</p>
  
  <p>The code used is this one : </p>
  
  <pre><code>package cnmodule;
  
  sub function1 {
  
    use strict;
    use Net::LDAP;
  
    my ($local) = @_;
    my $valueA;
  
    my $ldap = Net::LDAP-&gt;new('ad.network',version =&gt; 3) 
      or die "Can t connect to LDAP ($@)";
  
    $valueA = $ldap-&gt;bind ("cn=usercheck,cn=users,dc=domain,dc=network", password =&gt; 'password'); 
    $valueA-&gt;code &amp;&amp; die $valueA-&gt;error;
  
    $valueA= $ldap-&gt;search(
      base =&gt; 'dc=domain,dc=network',
      scope =&gt; 'sub',
      filter =&gt; '(sn=$local)', 
    );
  
    $ldap-&gt;unbind();
  
    $valueA-&gt;code &amp;&amp; die $valueA-&gt;error;
    foreach my $entry ($valueA-&gt;all_entries) {
      my $valueB = $entry-&gt;get_value('CN'); 
    }
    return $valueB;
  }
  
  $variableA='test';
  $variableB=function1($variableA);
  print $variableB;
  1;
  </code></pre>
  
  <p>The variable "$local" contains the name I need to do the search and is used in the ldap filter, but with this script LDAP doesn't receive the content of this variable and therefore doesn't return anything.</p>
  
  <p>Does anyone have a solution for me?</p>