matze77 has asked for the wisdom of the Perl Monks concerning the following question:

Hello!
I got a list with a bunch of user names which i need to generate user accounts and in a later step mail adresses.
Which modules e.g. would you suggest or maybe you already got a script which i could modify to my needs ...?
The input file could be in plain text, .csv or anything useful ...
I wasnt using perl for a longer time so i dont want to start from scratch if possible ;-). Thats the input file:

Max Maier Jerome Mustermann ...
Thats what it should look like:
Max Maier mmaier max.maier Jerome Mustermann jmustermann jerome.mustermann

Thanks
MH

Replies are listed 'Best First'.
Re: generate list from users first name and name?
by daxim (Curate) on Sep 14, 2012 at 11:46 UTC
    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.

      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

        We had allwong @ ******.com. I wonder what was wrong with alwong.

      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
Re: generate list from users first name and name?
by choroba (Cardinal) on Sep 14, 2012 at 11:32 UTC
    Something like this?
    #!/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.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Wow.
      Thank you alot, thats a great start.
      Special characters are treated manually by search an replace ...
      MH