Problems? Is your data what you think it is? | |
PerlMonks |
Regex: Example works, plugging it into code doesn't.by EclecticScion (Novice) |
on Jun 14, 2013 at 15:38 UTC ( [id://1038979]=perlquestion: print w/replies, xml ) | Need Help?? |
EclecticScion has asked for the wisdom of the Perl Monks concerning the following question: Greetings, O monks; I am fairly new to Perl, and this is my first submitted question. I seek wisdom on a problem that looks extremely simple, but has been causing me a lot of grief. I wish to parse a string to find all-caps words of at least 3 characters. My example code looks like this:
This returns:
...as desired. However, when I try to plug this into my larger program, the code behaves oddly. Specifically, $finalline has the desired content, but @words usually ends up empty. The especially odd thing is that if I remove the "/g" above, @words will retrieve the first capitalized word, but if I put it back in, it will retrieve zero capitalized words(!) I have also tried adding "/gc" instead, without success. The code does more or less what it's supposed to apart from this bug (and a couple of others). Here is my code. As far as I can tell, the relevant bits (lines 150-153, marked as "#PROBLEM CODE!!!" below) are exactly the same as in my example, but do not work correctly. Any help would be greatly appreciated. (Addendum: I have since gone back and turned on "use strict", and declared all my variables ahead of time. This has not solved the problem.)
Update: Removed extraneous code; added new line (print (">>>$finalline<<</n");) Update 2: smls's solution works. Thanks smls! Update 3: Restored problem code (see below).
Back to
Seekers of Perl Wisdom
|
|