Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^4: Peculiar problem with Net::LDAPS and AD LDAP

by jcb (Parson)
on Feb 21, 2021 at 04:32 UTC ( [id://11128614] : note . print w/replies, xml ) Need Help??


in reply to Re^3: Peculiar problem with Net::LDAPS and AD LDAP
in thread Peculiar problem with Net::LDAPS and AD LDAP

Assuming that you need to change 'ABCD' into '\AB\CD', there should be an easier way:

sub enc_hex { my $out = unpack('H*', (shift)); $out =~ s/\G(..)/\\$1/g; return $out; }

This uses the regex engine to advance through the string two characters at a time, inserting backslashes before each pair in the output. See perlre and perlop for more details.