Testing your code is a great concept. Of course, we all have to agree on the specs so we can all agree on what tests are needed. Your code works just fine for a certain subset of possibilities, dbwiz's code works just fine for a different subset of possibilities, both work just fine for the subset of posssibilities as presented by the OP. In the absence of a better spec, we all make assumptions that show the world that we, individually, live in more than they show the world that the OP lives in. (Which is why, if you look back at questions I pose, they're usually quite long-winded - to reduce the "absence of a better spec".)
As for the initial letters, not that we're straying from the initial thread here ;-), I'd recommend matching with /^([[:alpha:]]*)/ instead. Again, we have to agree on a spec of what "initial letters" means (does it mean English letters, or can it include accented characters, or letters in other non-Roman lettering systems?). If it includes other languages, I like letting perl worry about that stuff for me ;-). Note that it is perfectly reasonable to only accept straight-ascii for some things. We just can't tell from what has been stated so far. (And I've just revealed a bit more about the world I live in.)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
Outside of code tags, you may need to use entities for some characters:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||