Re: (Net::LDAP) Automatically convert attributes into utf8 when writting
pe rl <[email protected]> Mon, 31 Aug 2015 09:42:09 +0200
| Newsgroups | gmane.comp.lang.perl.modules.ldap |
|---|---|
| Message-ID | <[email protected]> |
Thank you for your information. Finally I added "uf8::encode" to all the attribs, so now it works. Converting our code (@_ and file i/o) into utf8 was an option, but I disc= arded it because we have a lot of files (our proyect is nearly a framewor= k, not a few files), including modules that read translation string files= for several languages, so converting everything into utf8 would be a lot= of extra work. Our proyect is rather old, it was created in the old times, when utf8 was= still not used. This is the reason why it is so difficult for us to conv= ert everyting into utf8. Anyway I believe we will have to convert it some= day, as you proposed. Thank you 29.08.2015, 13:54, "Peter Marschall" <[email protected]>: > Hi, > > On Tuesday, 25. August 2015 13:37:15 pe rl wrote: >> =9AThey are not necessary when reading/searching in the ldap server, s= ince >> =9ANet::LDAP already has a "raw" option in the constructor to automati= cally >> =9Aencode/decode strings. It is working for us, and the only change re= quired >> =9Ahas been to add the "raw" option to the constructor. > > I think you misinterpret the purpose of the raw option. > > Its goal is to convert the byte strings coming from the LDAP server tha= t > represent UTF-8 encoded directory strings from byte semantics to > Perl scalars with character semantics. > > On the other hand, perl-ldap expects scalars in character semantics whe= n > it comes to writing directory strings to an LDAP server. > > It is not perl-ldap's job to translate between scalars in Perl's charac= ter > semantics and various input or output encodings of your application. > >> =9AThe problem appears when writting to the ldap server. I have starte= d to >> =9Amodify our code with utf8::encode(), by adding it to every attribut= e in all >> =9Aof our functions. The problem is that it is very inefficient, since= I will >> =9Ahave to modify every attribute that appears in our programs. We hav= e a lot >> =9Aof functions that create/modify/delete entries in the ldap server, = so I >> =9Awill have to change a lot of code to manually encode attribs to utf= 8, and >> =9Athen test all of the changes. > > It is not perl-ldap's job to translate between scalars in Perl's charac= ter > semantics and various input or output encodings of your application. > > This is the application's task. > If you - as you write - need to convert every attribute using ut8::enco= de(), > then your application seems to use a mixture of byte & character semant= ics. > > In that case please do yourself a favour and switch over to character > semantics by correctly converting input to character semantics when it > happens: > - for file & console input you can use the ":encoding(...)" layer to ma= ke > =9A=9Asure you get character semantics instead of byte semantics > - for @ARGV a simple > =9A=9A=9A=9A=9A$_ =3D Encode::decode('UTF-8' ,$_) for @ARGV; > =9A=9Ashould be sufficient. > > You may also have a look at the 'utf8::all' package that does a lot of = the > above for you automatically. > > Please read the perlunicode manual page for more detailed information. > > Best > PEter > > -- > Peter Marschall > [email protected]