i'm working with DBI and Net::Ldap::Ldif - trying to write an app that populates a multidimensional array from a database query - then iterates through the data in the multidimensional array, writing to an ldif file. code is below, when i run it i get 'Entry 'username' is not a valid Net::LDAP::Entry object. at .line 96'
#!/opt/bin/perl # # NON-production program to generate ldif dump from mcdb table passwd # $Id$ # $Revision$ # $Source$ # use strict; $^W++; use DBI; use Getopt::Long; use Net::LDAP::LDIF; use Net::LDAP; use Net::LDAPS; #variables for options my $debug = ''; #debug mode my $passwd = ''; #update passwd info my $help = ''; #help msg my $verbose = ''; #verbose mode my $ldif = ''; #ldif file to write to my $entry = ''; #passwd entries my $i = ''; #counter my $fh = ''; #file handle #get the options and set up GetOptions( "help" => \$help, "debug" => \$debug, "verbose" => \$verbose, ); if ( $help ) { print <<EOH USAGE: ldif_parse_db_other.pl [Options] --help - display this text --verbose - give stats on what we did on exit EOH ; exit(); } #connect to the db warn "Connecting to the database\n" if $debug; my $dbh = DBI->connect("dbi:Sybase:server=localhost;port=4100", "", "" +); $dbh->do("use mydb"); #get data from passwd table my $sth = $dbh->prepare( "select login,password,crypt,uid,gid,gecos,home,shell from nsit..p +asswd" ); #defines for field positions my $PWLOGIN = 0; my $PWPASSWORD = 1; my $PWCRYPT = 2; my $PWUID = 3; my $PWGID = 4; my $PWGECOS = 5; my $PWHOME = 6; my $PWSHELl = 7; $sth->execute() || die; #load up multidimensional array my $pwarray = $sth->fetchall_arrayref(); #load all results into mul +ti-dimensional array my %pwarrayindex; warn "Indexing Information ... \n" if $debug; for ( $i = 0; $i < scalar(@$pwarray); $i++ ) { if ( exists( $pwarrayindex{ $pwarray->[$i][0] } ) ) { $pwarrayindex{ $pwarray->[$i][0] } .= ",$i"; #add the index + number } else { $pwarrayindex{ $pwarray->[$i][0] } = $i; } } #open up ldif file for writing $ldif = Net::LDAP::LDIF->new( $fh, "w" ); #load up the ldif file for ( $i = 0; $i < scalar(@$pwarray); $i++ ) { print qq($pwarray->[$i][0]); print qq($pwarray->[$i][1]); print qq($pwarray->[$i][2]); print qq($pwarray->[$i][3]); print qq($pwarray->[$i][4]); print qq($pwarray->[$i][5]); print qq($pwarray->[$i][6]); print qq($pwarray->[$i][7]); $ldif->write($pwarray->[$i][0]);//string $ldif->write($pwarray->[$i][1]);/string $ldif->write($pwarray->[$i][2]);//string $ldif->write($pwarray->[$i][3]);//int $ldif->write($pwarray->[$i][4]);//int $ldif->write($pwarray->[$i][5]);//string $ldif->write($pwarray->[$i][6]);//string $ldif->write($pwarray->[$i][7]);//string } $ldif->done();
any advice appreciated.

Edited by planetscape - added readmore tags


In reply to working with DBI and Net::Ldap::Ldif by philosophia

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.