title: Need help parsing results from ldap to csv
body: <p>I am trying to create a script to generate a csv file with the results of some ldap queries using Net::LDAP but I'm having troubles skipping incomplete lines if one element of the @attributes array is blank.</p>
  
  <pre><code>my @attributes  = ('cn', 'mail', 'telephoneNumber');
  </code></pre>
  
  <p>So for example, if a user has no mail listed, or no telephoneNumber listed, then it should skip the hold field instead of returning:</p>
  
  <pre><code>"Foo Bar",, # this line should be skipped since there is no mail nor telephone
  "Bar Foo","bar@foo.com", # this line should be skipped too, no number listed
  "John Dever","john_dever@google.com","12345657" # this one is fine, has all values
  </code></pre>
  
  <p>My loop right now is looking like this:</p>
  
  <pre><code># Now dump all found entries
  while (my $entry = $mesg-&gt;shift_entry()){
      # Retrieve each fields value and print it
      # if attr is multivalued, separate each value
      my $current_line = ""; # prepare fresh line
      foreach my $a (@attributes) {
          if ($entry-&gt;exists($a)) {
              my $attr = $entry-&gt;get_value($a, 'asref' =&gt; 1);
              my @values  = @$attr;
              my $val_str = "";
              if (!$singleval) {
                  # retrieve all values and separate them via $mvsep
                  foreach my $val (@values) {
                      if ($val eq "") { print "empty"; }
                      $val_str = "$val_str$val$mvsep"; # add all values to field
                  }
                  $val_str =~ s/\Q$mvsep\E$//; # eat last MV-Separator
              } else {
                  $val_str = shift(@values); # user wants only the first value
              }
  
              $current_line .= $fieldquot.$val_str.$fieldquot; # add field data to current line
  
          }
          $current_line .= $fieldsep; # close field and add to current line
      }
      $current_line =~ s/\Q$fieldsep\E$//; # eat last $fieldsep
      print "$current_line\n"; # print line
  }
  </code></pre>
  
  <p>I have tried code like :</p>
  
  <pre><code>if ($attr == "") { next; }
  if (length($attr) == 0) { next; }
  </code></pre>
  
  <p>and several others without any luck. I also tried simple if () { print "isempty";  } debug tests and its not working. Im not exacly sure how could I do this.</p>
  
  <p>I appreciate any help or pointers you could give me on what am I doing wrong.</p>
  
  <p>Thanks a lot in advance for your help.</p>
  
  <p><strong>UPDATE:</strong><br>
  Per chaos request:  </p>
  
  <pre><code>my $singleval = 0;
  </code></pre>
  
  <p>A sample run for this program would return:  </p>
  
  <pre><code>Jonathan Hill,Johnathan_Hill@example.com,7883                  
  John Williams,John_Williams@example.com,3453                     
  Template OAP,,                                            
  Test Account,,                                                
  Template Contracts,,
  </code></pre>
  
  <p>So what I want to do is to skip all the lines that are missing a field, either email or extension number.</p>