Dear great PERL masters,
This is my first major code in perl that works. It creates an LDIF file for
our openLDAP server.
So aside from use strict (YES I KNOW, but i started this project well
before I learnt that, and I couldn't be buggered going through and changing
it all) what else is wrong with this code. It works but how can it work
better...
input file is along the lines of:
name,surname,[EMAIL PROTECTED],56789,molecular
repeated to about 60 lines...
#############################################
#Code begins HERE
#############################################
use warnings;
#Main Program Begins Here
open (ADDSRC, "data.csv") || die ("Unable to open file\n");
@addsrc=<ADDSRC>;
splice (@addsrc,0,1);
foreach $line (@addsrc)
{
@addarr = split(/,/, $line);
push @fname, $addarr[0];
push @sname, $addarr[1];
push @email, $addarr[2];
push @exten, $addarr[3];
chomp $addarr[4];
push @section, $addarr[4];
}
@data = (\@fname, \@sname, \@email, \@exten, \@section);
close (ADDSRC);
open (LDIF, ">mdudat.ldif") || die ("Unable to write to file!\n");
print LDIF "#Base level\n";
print LDIF "dn: dc=mdu\n";
print LDIF "objectclass: top\n";
print LDIF "objectclass: organization\n";
print LDIF "o:mdu\n";
print LDIF "description: This is MDU's base dn.\n\n";
print LDIF "#staff list\n";
print LDIF "dn: dc=staff,dc=mdu\n";
print LDIF "objectclass:top\n";
print LDIF "objectclass:organizationalunit\n";
print LDIF "ou:staff\n";
print LDIF "Description: This is the tree where MDU's Staff are stored\n\n";
for $i ( 0 .. $#fname )
{
print LDIF "dn: cn=$data[0][$i] $data[1][$i],dc=staff,dc=mdu\n";
print LDIF "objectclass: inetorgperson\n";
print LDIF "cn:$data[0][$i] $data[1][$i]\n";
print LDIF "sn: $data[1][$i]\n";
$c = ($data[4][$i] =~ s/\//\//g);
if ($c eq "")
{
print LDIF "sn: $data[4][$i]\n";
}
else
{
@array = split(/\//,$data[4][$i]);
$j = scalar(@array);
$j--;
for $d (0 .. $j)
{print LDIF ("sn:",$array[$d],"\n");}
}
print LDIF "mail: $data[2][$i]\n";
print LDIF "telephonenumber: $data[3][$i]\n\n";
}
close (LDIF);
##############
#end code
##############
This was done on activeperl for Win32...
Michael Carmody
MDU, Public Health Lab
Dept. of Microbiology and Immunology
The University of Melbourne, Parkville
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]