Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Special Variable Pattern Match whilst reading input from a file

by dakkar (Hermit)
on Mar 29, 2003 at 19:53 UTC ( #246641=note: print w/replies, xml ) Need Help??


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:

"abc123def"=~/([a-z]+(\d+)(.*))/; print "first: $1\nsecond: $2\nthird: $3\n";
would print:
first: abc123def
second: 123
third: def

-- 
        dakkar - Mobilis in mobile

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://246641]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2022-05-25 04:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (84 votes). Check out past polls.

    Notices?