Troubles with special characters in Perl

Posted on 2000-03-22
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 ?
Question by:grivera032200
  • 2
  • 2

Author Comment

ID: 2645897
Adjusted points from 50 to 100
LVL 84

Expert Comment

ID: 2646053
($string = "México") =~ tr/é/e/;

Accepted Solution

sniperrus earned 100 total points
ID: 2770883
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.

Author Comment

ID: 2771350
Thanks for comments,
LVL 84

Expert Comment

ID: 2771364
/ig is invalid syntax for tr
Also, translating [ to [, and ] to ] is not very useful.

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

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…
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 (…
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

896 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

12 Experts available now in Live!

Get 1:1 Help Now