jm wrote:

Shawn and John,

thanks, your leads gave me this:

#############################################
#!/usr/bin/perl

print&surname($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 $name = shift;
        $name = join(' ', split(' ', $name));
        $name =~ s/(^[Mm]a?c|.')(.*)/\u$1\u$2/;
        return(ucfirst($name));
}       #       end of  sub surname
#############################################

John, to answer some of your questions:
the hash was legacy from earlier subs i've created, to allow for a
more generic structure.  i don't forsee that necessity here so i
changed to a scalar.
i also changed the first regex to use a?; not as comfortable with
regex's as i'd like yet.
the 2nd regex was required to allow the pos function to extract the
position of the desired character.  per the docs, the /g is a
requirement for pos (at least as i understand it).

You could use the @+ and @- arrays to find the start and end position of a regular expression.

perldoc perlvar


since 'mac'  is ignored by the substitution (as is any other
'conventional' name) the ucfirst takes care of all those upon
return().

i'm thinking about trying to include the whitespace cleanup in the
s/// but i'm thinking it'll be an ugly piece of code i'll always have
trouble understanding.



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