http://qs321.pair.com?node_id=596635


in reply to Re^3: Newbie parsing problem
in thread Newbie parsing problem

great solutions, I have noticed that:
my ($last, $first, $middle) = ($name =~ /(\w+)\W*?(\w+)\W*(\w)?/);
doesn't handle lastnames with hypens in them, any ideas? thanks again!

Replies are listed 'Best First'.
Re^5: Newbie parsing problem
by mk. (Friar) on Jan 26, 2007 at 12:21 UTC
    \w only matches letters, digits and underscores. since the hyphen is a non-word (\W), that regex interprets it as a separator, so that the second part of the last name is considered the first name.
    the following code supports hyphenated first and last names:
    my ($last, $first, $middle) = ($name =~ /([\w-]+)\W*?([\w-]+)\W*(\w)?/);

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    *women.pm
      ahhh, I see! thanks again for all your help!