Solved

Troubles with special characters in Perl

Posted on 2000-03-22
5
163 Views
Last Modified: 2010-03-05
I´m from Mexico, i want to manipulate strings in Perl which had character "´", for example, i want manipulate word México and convert to Mexico ¿ how can i do that ?
0
Comment
Question by:grivera032200
  • 2
  • 2
5 Comments
 

Author Comment

by:grivera032200
Comment Utility
Adjusted points from 50 to 100
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
($string = "México") =~ tr/é/e/;
0
 

Accepted Solution

by:
sniperrus earned 100 total points
Comment Utility
Tr/// is really your best shot, just compile a list of characters to be replaced and the list or replacement characters and execute something like :

$string =~ tr/[é¿]/[e ]/ig;

The elements of the left list are replaced with the corresponding elemnts in the right list. The i and g switches tell the command to make the substitutions on a case insensitive basis (although you are better off providing alternatives in respective cases for this) and to make substitutions globally, i.e. not to stop with only one substitution.
0
 

Author Comment

by:grivera032200
Comment Utility
Thanks for comments,
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
/ig is invalid syntax for tr
Also, translating [ to [, and ] to ] is not very useful.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

11 Experts available now in Live!

Get 1:1 Help Now