Mário Gamito wrote:
Hi,

I have this file in the following format:

tarta 16340309 marsanpin [EMAIL PROTECTED]
lms doom123 Luis Miguel Sequeira [EMAIL PROTECTED]
jura teste Juraci [EMAIL PROTECTED]
jsilva t00lt0ya5 Jorge Silva [EMAIL PROTECTED]
tchock  mail#4829 tchock  [EMAIL PROTECTED]
reporterx noname Duarte Oliveira [EMAIL PROTECTED]
erkulix brunoverab4 Bruno Cruz

First field is a username;
Second field is a password in clear text;
*Last field* is the email;
The field between is the name.

As you can see, some lines don't have the name, and names have a variable
number of words. Some lines don't have the e-mail.

What i need is:
Change the second field to the correspondent md5 hash.
Insert [EMAIL PROTECTED] in the end of the lines that have no email.
Insert the string "NO_NAME" in the ones that don't have a name in it's
field.
Substitute spaces for ":", *except* of course the spaces within the name.
At the end of each line add the string ":user" (without the quotes).

In the end, a perfect line is something like:
gamito:b31dda31342d6dfg6537342c1bc3852d:Mario Gamito:[EMAIL PROTECTED]:user

I know how to do some of these things, others i don't.

Can someone help me, please ?

I've chosen to just throw a program together rather than help you to solve this
yourself. I disapprove of this sort of reply on a beginners' list but I'm
lacking the impetus to be more constructive I'm afraid!

You don't seem to have show any records that have no name field, unless I'm
misunderstanding you.

Also your MD5 string has a 'g' in it and therefore can't be hex. It also has no
zeroes, and I wonder if this is a format that I've never come across before that
is 1-based hex, or is it simply a mistake on your part?

Anyway the program below should otherwise do what you want.

HTH,

Rob


use strict;
use warnings;

use Digest::MD5 qw/md5_hex/;

while (<DATA>) {

  my @field = split;

  my ($user, $pass) = splice @field, 0, 2;
  my $email = $field[-1] =~ /\@/ ? pop @field : '[EMAIL PROTECTED]';
  my $name = "@field" || 'NO_NAME';

  print join(':', $user, md5_hex($pass), $name, $email, 'user'), "\n";
}

__DATA__
tarta 16340309 marsanpin [EMAIL PROTECTED]
lms doom123 Luis Miguel Sequeira [EMAIL PROTECTED]
jura teste Juraci [EMAIL PROTECTED]
jsilva t00lt0ya5 Jorge Silva [EMAIL PROTECTED]
tchock  mail#4829 tchock  [EMAIL PROTECTED]
reporterx noname Duarte Oliveira [EMAIL PROTECTED]
erkulix brunoverab4 Bruno Cruz
uname pass [EMAIL PROTECTED]

**OUTPUT**

tarta:dec89501d8c52600d0dc4a36b6a3684c:marsanpin:[EMAIL PROTECTED]:user
lms:0e5ed9c664e4d963c8068d1f432a06c9:Luis Miguel Sequeira:[EMAIL PROTECTED]:user
jura:698dc19d489c4e4db73e28a713eab07b:Juraci:[EMAIL PROTECTED]:user
jsilva:01445d071f1c9552d06b0c345bf496fe:Jorge Silva:[EMAIL PROTECTED]:user
tchock:bbb42081ecc5aa7b9b63c5aebaff38e7:tchock:[EMAIL PROTECTED]:user
reporterx:499ddaad9df107bf7107a3e2c0064800:Duarte Oliveira:[EMAIL 
PROTECTED]:user
erkulix:235024626f7047367ee61468d83ec7bd:Bruno Cruz:[EMAIL PROTECTED]:user
uname:1a1dc91c907325c69271ddf0c944bc72:NO_NAME:[EMAIL PROTECTED]:user


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to