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

Re: Multiple regex catches on a line

by stephen (Priest)
on Jun 20, 2001 at 04:06 UTC ( #89871=note: print w/replies, xml ) Need Help??


in reply to Multiple regex catches on a line

When you call m/regex/g in scalar context, it first returns the first occurrance of regex. If you call it again, it'll return the second occurance of regex, and so on.

In using if, you're only calling the regexp once per line. Change it to this:

while (<file>) { while (/(regex1|regex2|regex3)/gi) { f($1); } }

Update: Added the 'g' modifier. Thanks to Hofmator for keen eyes.

stephen

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://89871]
help
Chatterbox?
stevieb is writing a little CUFP on how to control analog pins on an arduino from a Linux machine via I2C in light of Perl, JavaScript and Strandbeests. It also is a good real-world use-case to test my I2C dist.
[stevieb]: I just don't feel like going hardcore on anything today, so I thought I'd *use* my software instead of just write it
[beech]: let the surprises begin :D

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2017-07-21 23:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (336 votes). Check out past polls.