Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: running riot with an regx on surnames.

by trantor (Chaplain)
on Nov 27, 2001 at 14:46 UTC ( [id://127770] : note . print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    foreach ($first,$last) {
            s/^\s+//;
            s/\s+$//;
    }
    
  2. or download this
    if ($last =~ m/\d/g) {
            die "Surname should only contain letters, hyphens and apostrop
    +hes!";
    }
    
  3. or download this
    elsif ($last =~ m/(\w+)\s*(\w+)/) {
            $surname = join(' ', $1, $3);
    }
    
  4. or download this
    #!/usr/bin/perl -w
    
    use strict;
    ...
    my $n = 'Joe De Blogg';
    my($name, $surname) = split /\s+/, $n, 2;
    print "name: $name surname: $surname\n";