Well, I certainly am glad I just picked up the new Camel book. I had been having quite a time trying to find patterns common to multiple strings. I had sample input of two strings "ABCD". For each 1,2,3 and 4 character substring there should have been 2 matches, right? Not so. My original code looked liked this (relevant part only):
$all{$str} += $packets[$_] =~ /$str/g;
When I ran it against the sample input, I got weird output. For example, two character substring matches:
- AB - 2 matches (good!)
- BC - 0 matches (eh?)
- CD - 2 matches (good again!)
Any combination would produce the weird 2,0,2,0, etc pattern of matching.
Following much frenzied thumbing through the Camel, I ran across almost an offhand mention to pos. I added the line
pos $_ = 0; after the previous line, and now the counts work perfectly.
I feel good that I managed to find this one by reading the FM, but also feel that I should mention it since it never came up in any of the (wonderful!) responses I've received to the
pattern matching problem and
its revisit.