utilisation de text::csv pour le parsing
recuperation en tete de colonne modifications des entrées sans conditions
This commit is contained in:
28
test.pl
28
test.pl
@@ -5,6 +5,7 @@
|
|||||||
# d'un fichier csv passé en argument
|
# d'un fichier csv passé en argument
|
||||||
use strict;
|
use strict;
|
||||||
use Net::LDAP;
|
use Net::LDAP;
|
||||||
|
use Text::CSV;
|
||||||
|
|
||||||
my $ldapserver = "localhost";
|
my $ldapserver = "localhost";
|
||||||
my $binddn = "cn=manager,o=od";
|
my $binddn = "cn=manager,o=od";
|
||||||
@@ -17,21 +18,32 @@ my $mesg = $ldap->bind( $binddn,
|
|||||||
);
|
);
|
||||||
|
|
||||||
$mesg->code and die $mesg->error; # check for errors
|
$mesg->code and die $mesg->error; # check for errors
|
||||||
|
my $csv = Text::CSV->new({ sep_char => ';' }) ;
|
||||||
my $file = $ARGV[0] or die "Need to get CSV file on the command line\n" ;
|
my $file = $ARGV[0] or die "Need to get CSV file on the command line\n" ;
|
||||||
|
|
||||||
open(my $data, '<', $file) or die "Could not open '$file' $!\n";
|
open(my $data, '<', $file) or die "Could not open '$file' $!\n";
|
||||||
while (my $line = <$data>) {
|
my @cols = @{$csv->getline ($data)};
|
||||||
chomp $line;
|
foreach my $c (@cols){
|
||||||
my @fields = split ";" , $line;
|
print "columne: ". $c ."\t" ;
|
||||||
my $dn = $fields[0] ;
|
}
|
||||||
my $attr1 = $fields[1] ;
|
my $row = {} ;
|
||||||
|
$csv->bind_columns (\@{$row}{@cols});
|
||||||
|
while ($csv->getline ($data)) {
|
||||||
|
my $dn = $row->{dn} ;
|
||||||
|
my $attr1 = $row->{seeAlso} ;
|
||||||
|
my $attr2 = $row->{l} ;
|
||||||
|
|
||||||
|
# my $mesg = $ldap-> search(
|
||||||
|
# base=> $dn,
|
||||||
|
# scope=> "base",
|
||||||
|
# filter=> "(description=".$attr1.")") ;
|
||||||
|
# print $mesg->count() ;
|
||||||
|
# if ($mesg->count() != 0) { next ; }
|
||||||
print( $dn."\t".$attr1."\n" ) ;
|
print( $dn."\t".$attr1."\n" ) ;
|
||||||
my $mesg = $ldap-> modify( $dn,
|
my $mesg = $ldap-> modify( $dn,
|
||||||
changes=> [
|
changes=> [
|
||||||
delete => [ 'description' ],
|
replace => [ 'description'=> $attr1 ],
|
||||||
add => [ description => $attr1 ]
|
replace => [ 'l' => $attr2 ],
|
||||||
]
|
]
|
||||||
) ;
|
) ;
|
||||||
$mesg->code and warn $mesg->error; # check for errors
|
$mesg->code and warn $mesg->error; # check for errors
|
||||||
|
|||||||
Reference in New Issue
Block a user