P is for Practical | |
PerlMonks |
Re: Word Count and Matchby davido (Cardinal) |
on Jan 07, 2021 at 21:22 UTC ( [id://11126559]=note: print w/replies, xml ) | Need Help?? |
So... an adaptation of the code you presented works as you seem to want:
This produces:
There's no extra output with some total count. Your problem would be a lot easier to diagnose if you supplied us with the following:
Currently we're debugging code that probably isn't the code you are running, and we're only able to guess at what the data looks like. I don't think you need the /o modifier for your regular expression; it doesn't do anything useful nowadays. And it's probably better to use $wordcnt = qr/Bob|Tom..../; instead regular quotes, though that's not strictly necessary. You should probably surround your pattern match with \b anchors for word boundaries so that you don't match "Bob" for the name "Bobby". Your alternation is also silly; what are repeated alternates supposed to do? I scanned back through some of your previous posts over the past seventeen years; you've been asked to provide real code and sample input and output in the past. Dave
In Section
Seekers of Perl Wisdom
|
|