in reply to Re: Regexp and substitution question
in thread Regexp and substitution question

Absolutely - I can't emphasize enough how important it is to get in the habit of explicitly capturing your matches. It's easy to get lazy about using the values right away, and then your program develops mysterious bugs when someone else adds a "harmless" function call that invokes something else that internally does a pattern match, but only sometimes...

I also recommend getting into the habit of naming your captures; that way it's much clearer: "now does $capture[4] contain the right value, or was it $capture[3]?". If you do this:

my($name, $age, $weight) = ($line =~ /$pattern/);
you'll be much less likely to set someone's age to 180 and their weight to 40.