Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

escaping special charcters from a string

by bar10der (Beadle)
on Nov 07, 2005 at 13:09 UTC ( #506320=perlquestion: print w/replies, xml ) Need Help??

bar10der has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

For LDAP password authentication I need to escape any special characters that might be in the password.

I tried my best but so far can not find my way out. There is addslashes function in PHP which does the job. Is there any function similar to this in perl? Can some one give me an example, please

Thanks in advance for your help.

  • Comment on escaping special charcters from a string

Replies are listed 'Best First'.
Re: escaping special charcters from a string
by g0n (Priest) on Nov 07, 2005 at 13:37 UTC
    According to this the php addslashes function does the following:

    string addslashes(string str)
    Escapes single quote, double quotes and backslash characters in a string with backslashes

    which you can do with:

    $string =~s/(['"\\])/\\$1/g;

    --------------------------------------------------------------

    "If there is such a phenomenon as absolute evil, it consists in treating another human being as a thing."

    John Brunner, "The Shockwave Rider".

Re: escaping special charcters from a string
by pboin (Deacon) on Nov 07, 2005 at 13:27 UTC

    You might want to take a look at quotemeta. Try 'perldoc -f quotemeta' to get a quick overview.

    Update: added direct link to doc.

Re: escaping special charcters from a string
by sgifford (Prior) on Nov 07, 2005 at 16:48 UTC
    Does the LDAP module you're using provide any way to handle the escaping for you? That's likely to be easier, faster, work better, and be more secure, since whoever wrote the LDAP module probably knows more about LDAP than you or I. :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://506320]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2021-09-20 08:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?