Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

generate list from users first name and name?

by matze77 (Friar)
on Sep 14, 2012 at 11:19 UTC ( [id://993700]=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://993700]
Approved by chacham
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-03-29 12:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found