maderman has asked for the wisdom of the Perl Monks concerning the following question:
The problem with the above is that for names like Joe de Bloggs, I get "J De" returned and not "J De Bloggs". A little help here? Many thanks in advance. Stacy.use strict; if ($reporter !~ m/(\w+)\s*(.*)/) { die "Name should be in wrong format"; } else { $first = $1; $last = $2; #remove leading/trailing whitespace foreach ($first,$last) { s/^\s+//; s/\s+$//; } if ($first !~ m/[A-Za-z]/) { die "First name should only contain letters!"; } if ($last =~ m/\d/g) { die "Surname should only contain letters, hyphens and apostrophe +s!"; } elsif ($last =~ m/([A-Za-z\'\-]+)/) { $surname = $1; } elsif ($last =~ m/(\w+)\s*(\w+)/) { $surname = join(' ', $1, $3); } else { die "Wrong format in surname!"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Parsing english names
by boo_radley (Parson) on Nov 27, 2001 at 11:15 UTC | |
|
Re: running riot with an regx on surnames.
by trantor (Chaplain) on Nov 27, 2001 at 14:46 UTC | |
|
Re: running riot with an regx on surnames.
by Dogma (Pilgrim) on Nov 27, 2001 at 12:16 UTC | |
|
Re: running riot with an regx on surnames.
by jarich (Curate) on Nov 27, 2001 at 15:55 UTC | |
|
(joealba) Devil's advocate time...
by joealba (Hermit) on Nov 27, 2001 at 19:41 UTC |