|
|
| "be consistent" | |
| PerlMonks |
Re^2: Error in my Regular expression patternby Anonymous Monk |
| on Mar 18, 2012 at 07:28 UTC ( #960267=note: print w/ replies, xml ) | Need Help?? |
|
Like perlop#m/PATTERN/msixpodualgc ( perlop#m// ), says, m// in scalar context returns true if it succeeds, false if it fails. Each time m// succeeds against a variable, like when $n = m/twinkle/ig; executes, position is changed, so that while(/twinkle/ig) { executes, only the second twinkle is counted. If you add this to your program before the while loop this resets pos associated with $_, and then your program will produce
Like perlfaq4 says, if you want the number of occurances, use the flying lentil operator, use
my $count =()= m/twinkle/ig;
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||