Panel Vincent - A53 wrote at Tue, 27 Aug 2002 17:47:09 +0200: > As my first real script in perl, I would to parse a LDIF file (export format > of an LDAP directory) to get some sort of information of it. The structure > of such a file is something like this (between quotes) : > > " > name: bozo > surname: the clown > address: over here ^^ > > name: denise > surname: richard > address: in your dreams ^^ > > name: brad > surname: pitt > adress: there ^
Sometimes address with 2 d and sometimes with only one d ?! > " > > What should be the structure of my loop ? Do you know a complete script > already written to parse such a file (can't find any on the net) ? What have you tried so far ? Could be that there are already some modules. I've never had to parse LDIF files, but a CPAN search has some results: http://search.cpan.org/search?mode=all&query=ldif If I would have to do it for my own, I would try something like: local $/ = "\n\n"; # Set an empty newline as line separator while (<LDIF_FILE>) { my ($name) = /^name: (.*)$/m; my ($surname) = /^surname: (.*)$/m; my ($address) = /^address: (.*)$/m; # or /^add?ress: (.*)$/ to match also adress # now work with the variables } Another approach is to read the variables into a hash local $/ = "\n\n"; # Set an empty newline as line separator while (<LDIF_FILE>) { my %person = map /^(.*): (.*)/, split /\n/; # now you can work with # $person{name} # $person{surname} # $person{address} } Best Wishes, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]