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";