No such thing as a small change | |
PerlMonks |
Re^5: Newbie parsing problemby mk. (Friar) |
on Jan 26, 2007 at 12:21 UTC ( [id://596700]=note: print w/replies, xml ) | Need Help?? |
\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)?/);
In Section
Seekers of Perl Wisdom
|
|