Solved

stripslashes in perl

Posted on 2002-07-11
4
1,326 Views
Last Modified: 2008-01-09
In Perl, how can I perform the same action that stripslashes does in php?
0
Comment
Question by:blackwolfsystems
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
smisk earned 75 total points
ID: 7147209
Shouldn't be too hard.  According to the php docs you just remove backslashes from \", \', and \\.

sub stripslashes() {

    $_ = shift();
    s/\\'/'/;
    s/\\"/"/;
    s/\\\\/\\/;

    return $_;

}
0
 

Author Comment

by:blackwolfsystems
ID: 7148673
Thanks I kind of guessed it would end up like that.

But that doesn't quite work, you have to do:
s/\\'/'/g;
s/\\"/"/g;
s/\\\\/\\/g;
instead as otherwise it only changes the first occurance.

Thanks for the help
0
 
LVL 1

Expert Comment

by:smisk
ID: 7149037
Thanks.  I must have missed the global option...
0
 
LVL 84

Expert Comment

by:ozo
ID: 7150909
s/\\([\\'"])/$1/g
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question