Perl: the Markov chain saw | |
PerlMonks |
Re: Need a better way to count input linesby hv (Prior) |
on May 07, 2004 at 16:15 UTC ( [id://351509]=note: print w/replies, xml ) | Need Help?? |
For Bo Jo Le Much, the problem occurs when you try to clean up $fname:
The /\s+/fragment requires one or more whitespace characters at the start, and when that isn't present the substitution fails.
The cleanest fix would probably be to absorb optional whitespace after the comma within the split, so that you don't need to look for it afterwards:
Note that I've extended the split command slightly: specifying a LIMIT of 2 ensures that trailing text will not be thrown away if for some reason there is more than one comma in the name. It also allows the split to execute slightly faster, since it doesn't need to scan for more commas after the first is found. Also, removing the need to check for whitespace in the substitution means that the only thing it is still doing is stripping non-word characters from the end, allowing a somewhat simpler pattern. Hugo
In Section
Seekers of Perl Wisdom
|
|