Don't ask to ask, just ask | |
PerlMonks |
Shot myself in the foot with a posby Guildenstern (Deacon) |
on Aug 10, 2000 at 18:22 UTC ( [id://27292]=perlmeditation: print w/replies, xml ) | Need Help?? |
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:
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.
Back to
Meditations
|
|