> -----Original Message-----
> From: Sudarshan Raghavan [mailto:[EMAIL PROTECTED]] 
> Sent: 19 September 2002 23:57
> To: Perl beginners
> Subject: Re: Regexp
> 
> 
> On Wed, 18 Sep 2002, Panel Vincent - A53 wrote:
> 
> > I would like to reformat names like
> > 
> >   Francois de   la Varenne
> > Macha Meril 
> > Buzz    Mac Cormack
> > 

> Use split instead of a regexp (perldoc -f split)
> Let us assume the input string is in $str, this should do the 
> job for you
> 
> my ($first, $rest) = split (/\s+/, $str, 2);
> $rest =~ s/\s+//g;
> print "$first.$last\@domain.top";
> 

split is the best way, but above split leads to empty leading values
> >   Francois de   la Varenne
would end up [EMAIL PROTECTED]


the following should work: (the split pattern is a one character space
rather than a regex)

my @words = split ' ', $name;
my $email = shift(@words) . '.' . join('',@words) . '@domain.top';
print "'$name' => '$email'\n";

--or--

my @words = split ' ', $name, 2;
my $email = $words[0] . '.' . $words[1] . '@domain.top';
$email =~ s/\s+//g;
print "'$name' => '$email'\n";


regards
Jeff


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to