shajiindia has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
I am using the following code and it gives a wrong result when run. I am trying to figure out but could not get the reason. Please help.
Number of occurences = 1
Found 1 times
but when I comment out lines 3 & 4 it gives the correct result. Why does the while loop produces the correct result when I comment out lines 3 & 4?
Found 2 times
When I run, it produces the following result$_ = "Twinkle twinkle little star"; $n = m/twinkle/ig; print "Number of occurences = $n\n"; while(/twinkle/ig) { $count++; } print "Found $count times\n";
Number of occurences = 1
Found 1 times
but when I comment out lines 3 & 4 it gives the correct result. Why does the while loop produces the correct result when I comment out lines 3 & 4?
Found 2 times
Back to
Seekers of Perl Wisdom