Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by dakkar (Hermit)
on Mar 29, 2003 at 19:53 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-19 06:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found