Jan 31, 2018, 8:10 AM
Post #3 of 3
I am not sure what you expect the /g to do. In list context, it returns a list of all matches. In scalar context, it returns the next match. In order for this to work, each search must start where the previous successful search ended. (It resets the starting point when the match fails)
Re: [shreyas_007] there is just a difference of /i in regular expression assigned to $a and it is producing different outputs.Why?
[In reply to]
Examine your four examples.
The first succeeds in scalar context. (returns 1, does not
reset starting position)
The second fails because there is no second match. In list context, it returns a single undefined.
The third fails because the case does not match. In scalar context, it returns false and resets the starting position.
The fourth finds and returns all matches (There is only one). This is different from the second example because it starts from the beginning rather than the end of 'When'.