Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re: Regex for Differentiating Underscore and Whitespaceby mwah (Hermit) |
on Nov 03, 2007 at 18:03 UTC ( [id://648816]=note: print w/replies, xml ) | Need Help?? |
neversaint: what's wrong with my script above such that it prints no underscore instead of with underscore There have been already correcting hints in all directions by moritz and CountZero. From analyzing your code, jasonk pointed out your misconception on /x and whitespace, which means your code would work as intended if you change the regex modifier to:
The /x modifier would lead the regex to ignore the space (as has been said) and the /m and /s aren't needed here (they don't do anything) In another response, grinder scrutinized your problem solution and offered a more efficient solution based on the index() function without any regular expressions. In addition to these hints, davido tackles the problem by an important feature of the tr// (transliteration) operator - to count occurrences of characters in very efficient way. This would reduce your problem to the following expression:
after which you may decide on the 'count' of the character in question. Regards mwa
In Section
Seekers of Perl Wisdom
|
|