LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-10-2004, 02:12 PM   #1
weird_guy
LQ Newbie
 
Registered: May 2003
Location: Brazil
Distribution: Red Hat 9 + Fedora
Posts: 22

Rep: Reputation: 15
removing accents with perl


I'm trying to make a script to find the login of a user given his full name . It works for names without accents , but for accents it fails (as all user names in the network have no accents).
So I tried this function to remove accents:

sub Transform {
local($str)= $_[0];
$str=~ s/\á/a/g;
$str=~ s/\é/e/g;
$str=~ s/\í/i/g;
$str=~ s/\ó/o/g;
$str=~ s/\ú/u/g;
$str=~ s/\â/a/g;
$str=~ s/\ê/e/g;
$str=~ s/\ô/o/g;
$str=~ s/\ã/a/g;
$str=~ s/\õ/o/g;
$str=~ s/\ç/c/g;
$str=~ s/\Á/A/g;
$str=~ s/\É/E/g;
$str=~ s/\Í/I/g;
$str=~ s/\Ó/O/g;
$str=~ s/\Ú/U/g;
return $str;
}

but it doesnt work. I tried to use s/"\x82"/a/ for example (dont know if 82 is the hex value of any accented "a" character ...) and it didnt work also... I preffer to use octal or hex values , because typing the accented char is problematic (the locale on each system can affect this..)..

Any ideas on how to make this work?
 
Old 03-10-2004, 05:45 PM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Your function works for me with the plain accented characters, no need to back-slashing them though (but it doesn't hurt either).
Perhaps is it the way the characters are coded in your script that differs from the way the characters are sent to the function.

Did you tried to test your function from inside ?
e.g.
print Transform("hello world éè\n");
 
Old 03-10-2004, 06:09 PM   #3
weird_guy
LQ Newbie
 
Registered: May 2003
Location: Brazil
Distribution: Red Hat 9 + Fedora
Posts: 22

Original Poster
Rep: Reputation: 15
it's weird.. I tried testing this way:

$test = "áéè test";
$test1 = &Transform($test);

and it worked...

I'm reading my input from a file . Is anything else that could be wrong?
 
Old 03-10-2004, 06:39 PM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
what editor are you using ?
what command are you using to run the filter ?
try to pass your program through itself to see if it removes its accents.
 
Old 03-10-2004, 07:44 PM   #5
weird_guy
LQ Newbie
 
Registered: May 2003
Location: Brazil
Distribution: Red Hat 9 + Fedora
Posts: 22

Original Poster
Rep: Reputation: 15
I'm using emacs. if I do:
./findlogin.pl findlogin.pl
it replaces the accents on the source of the program...
I guess I'm gonna do some tests on the input file...

edit:
weird.. I've created the input file again and now it works..

Last edited by weird_guy; 03-10-2004 at 07:46 PM.
 
Old 03-12-2004, 04:34 PM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Did you kept the old file ?
If true, you can do an "od -c" on both and see if the character coding differs.
 
Old 03-12-2004, 06:45 PM   #7
weird_guy
LQ Newbie
 
Registered: May 2003
Location: Brazil
Distribution: Red Hat 9 + Fedora
Posts: 22

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by jlliagre
Did you kept the old file ?
If true, you can do an "od -c" on both and see if the character coding differs.
I thought I would die without finding out what happened , so I simply deleted the file and created it again... well, at least now I know a new command..
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
setxkbmap no accents bobbens Linux - Software 0 03-17-2005 12:17 PM
Keyboard and accents... djib Mandriva 2 09-15-2004 12:07 PM
problems with accents and Ñs J0sep Red Hat 7 08-17-2004 04:05 PM
Removing Perl AMMullan Linux - Software 5 12-07-2003 01:28 PM
accents without deadkeys in openoffice messenjah Linux - Software 1 09-19-2003 01:06 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration