Solved

stripslashes in perl

Posted on 2002-07-11
4
1,285 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
binary to char / hexadecimal 5 104
Strange perl issue 6 125
Shell script to bind my job to half the number of vCPUs in Solaris 8 115
collecting information 2 135
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

919 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now