in reply to Special Variable Pattern Match whilst reading input from a file
Parenthesised matches always end up in the match variables $1, $2, ..., so you could write:
while (<CONFIG_FILE>) { if (/^frz\s+=\s+(\w+);/) {$bar=$1} }
If you have more than one pair of parenthesis, $1 will refer to the match of the first pair, $2 to the second and so on. The pairs are ordered from left to right, counting their opening parenthesis, so:
would print:"abc123def"=~/([a-z]+(\d+)(.*))/; print "first: $1\nsecond: $2\nthird: $3\n";
first: abc123def second: 123 third: def
-- dakkar - Mobilis in mobile
In Section
Seekers of Perl Wisdom