Ignorance is Bliss - non-memorizing parentheses
One of regular expressions’ most useful features is memorization. To do this, just put parentheses around part of your expression and the result will be memorized:
my($name) = /hello, (\w+)/
In this example, we look in $_ for the word “hello” followed by a comma, space, and a word. Since the word, \w+, has parentheses around it, the part of the string that it matches gets memorized. In this example, we are assigning the return value of the regular expression match to $name. So if $_ contains “hello, world” then $name gets “world” - very convenient.
But parentheses also do other things besides memorize their contents, and this feature can become annoying. Here’s an example. (more…)
