On Thu, Oct 7, 2010 at 1:22 PM, Shawn H Corey <shawnhco...@gmail.com> wrote:
> On 10-10-07 02:08 PM, jm wrote:
>>
>> it works as intended but i was wondering if anyone can suggest
>> improvements in size and efficiency
>
> See `perldoc perlre` and search for /\\u/, /\\U/, /\\l/, and /\\L/.
>
>
> --
> Just my 0.00000002 million dollars worth,
>  Shawn
>
> Programming is as much about organization and communication
> as it is about coding.
>
> The secret to great software:  Fail early & often.
>
> Eliminate software piracy:  use only FLOSS.
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


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).
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.

again, thanks for your help, gentlemen.
joe

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