Solved

Troubles with special characters in Perl

Posted on 2000-03-22
5
165 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
ID: 2645897
Adjusted points from 50 to 100
0
 
LVL 84

Expert Comment

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

Accepted Solution

by:
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.
0
 

Author Comment

by:grivera032200
ID: 2771350
Thanks for comments,
0
 
LVL 84

Expert Comment

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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…

825 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