On 10/28/05, David Gilden <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I am stuck with this issue.
> How do get each substring (the names in this case) and then upper case them.
> This does not work just yet....
>
> Possible data:
> mike smith
> john h. hamilton
> g. bush
> hendric
>
> etc......
> ----
>
> #!/usr/bin/perl
>
> $SendersName = " dave middlename gilden ";
> $SendersName =~ s/\s*(.+)\s*/$1/g;
> ($SendersName) = $SendersName =~ m/([\w\.-]{1,24}( [\w\.-]{1,24}){0,4})/;
> $SendersName =~ s/.+ (.+)? (.+){1,3}/\u$1 \u$2 \u$3/g;
> print "$SendersName\n";
>

It's going to be a whole lot easier, and probably just as fast, to use
split() and join() to break the strings apart and operate on each part
of the name separately. Also, once you've split the names, Perl has a
built-in ucfirst() function--see perldoc -f ucfirst--so you don't even
really need to write your own regex.

    $SendersName = join(' ', map {ucfirst($_)} split / /, $SendersName);

Names are more complicated tha you think, though. What will you do
with strings like 'old mcdonald', 'old macdonald', and 'c.j. price'?

HTH

-- jay
--------------------------------------------------
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.dpguru.com  http://www.engatiki.org

values of β will give rise to dom!

Reply via email to