use utf8;
use Text::Unidecode qw(unidecode);
sub short {
my @s = split ' ', (lc unidecode($_[0]) =~ tr/-//dr);
$s[0] = substr $s[0], 0, 1;
return join '', @s;
}
sub long {
return lc unidecode($_[0]) =~ tr/ /./r =~ tr/-//dr
}
printf "%s\t%s\t%s\n", $_, short($_), long($_) for (
'Ævar Arnfjörð Bjarmason',
'Jérôme Mustermann',
'Max Maier',
'Rafaël Garcia-Suarez',
'Rafael van der Vaart',
'विश्वनाथन आनंद',
'周潤發',
);
I can guess what you're up to. Don't just create account names! During sign-up, give these transformed names out as a suggestion, then let people confirm/change them. | [reply] [Watch: Dir/Any] |
Don't just create account names! During sign-up, give these transformed names out as a suggestion, then let people confirm/change them.
I'd like to second that, Imagine these poor guys and what you'll get...
Alexander Shole
Fabian Atas
Georg Ayman
Walter Hore
s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
| [reply] [Watch: Dir/Any] [d/l] [select] |
| [reply] [Watch: Dir/Any] [d/l] [select] |
Installed module from cpan, guess there might be missing some brackets e.g., maybe someone could help?:
Bareword found where operator expected at test-perl-name.pl line 4, ne
+ar "tr/-//
dr"
Bareword found where operator expected at test-perl-name.pl line 9, ne
+ar "tr/ /.
/r"
Can't modify non-lvalue subroutine call in transliteration (tr///) at
+test-perl-
name.pl line 4, near "tr/-//dr"
syntax error at test-perl-name.pl line 4, near "tr/-//dr"
syntax error at test-perl-name.pl line 9, near "tr/ /./r "
Execution of test-perl-name.pl aborted due to compilation errors.
Thanks
MH
| [reply] [Watch: Dir/Any] [d/l] |
#!/usr/bin/perl
use warnings;
use strict;
while (<DATA>) {
chomp;
my @names = map lc, split;
s/\.// for @names;
print join "\t",
$_,
lc substr($names[0], 0, 1) . $names[-1],
lc join '.', @names;
print "\n"
}
__DATA__
Max Maier
Jerome Mustermann
John Lee Duke
Peter F. Smith
Your treatment of the middle names might be different. Also, if there are non-ASCII characters in your users' names, more care is needed. Moreover, you should probably hash the usernames and e-mails and check for duplicates.
| [reply] [Watch: Dir/Any] [d/l] |
Wow.
Thank you alot, thats a great start. Special characters are treated manually by search an replace ...
MH
| [reply] [Watch: Dir/Any] |