jm wrote:
all,

Hello,

below is a sub i created to try to properly capitalize surnames of
irish/scottish descent, converting Macarthur =>  MacArthur, o'donnell
=>  O'Donnell, etc.

it works as intended but i was wondering if anyone can suggest
improvements in size and efficiency (realizing the two are not
necessarily compatible).
also rules for any additional naming styles would be appreciated since
the sites using this will have a fairly global audience, name-wise.

thanks in advance,
joe

#############################################

print&surname(NAME =>  $ARGV[0]) . "\n";


#       SUB SURNAME
#       removes leading/trailing whitespace
#       consolidates grouped whitespaces into single whitespaces
#       capitalizes first letter after "Mac/Mc/'" in name (names of
Scottish/Irish descent)
#       capitalizes first letter of name upon return
sub surname
{
        my %options = @_;

Do you really need a hash for a single value?  Why not just a scalar?


        #       $options{NAME} = name to capitalize internally, if appropriate

        #       remove leading and trailing whitespace, consolidate whitespace
groupings into single whitespaces
        $options{NAME} = join(' ', split(' ', $options{NAME}));

        if ($options{NAME} =~ /^M[a]*c|'/i)

Why the use of the character class with just one character? /[a]*/ and /a*/ do exactly the same thing. And does that mean that "Maaaaaaac" is valid because that is what the pattern matches. Perhaps you want /^Ma?c|'/i.


        {
                $options{NAME} =~ m/c|'/g;

Why are you running another regular expression? And why are you using the /g option?


                my $pos = pos $options{NAME};
                substr($options{NAME}, $pos, 1) = uc(substr($options{NAME}, 
$pos, 1));

What happens if $options{NAME} only contains "Mac"?


        }       #       end of  if ($options{NAME} =~ /^M[a]*c|'/)

        return(ucfirst($options{NAME}));
}       #       end of  sub surname

#############################################




John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to