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

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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://89871]
[erix]: yeah, you mediteraaneans are one big family :)
[Discipulus]: greece had to copyrigth etymologies to fill the debt..
[erix]: good no-nonsense american approach to these soft european practices: "Upon entering the Almshouses in Connecticut, patients were whipped up to 10 times"
Discipulus should have..
[erix]: the almshouse generally seems to have become an anglosaxon relic :P
[Discipulus]: just to be sure was not for a free lunch.. sbaaam!
[Discipulus]: here now we call them Cities
[erix]: 'cities'? in italian? are they funded by charity?
[LanX]: The New Testament was first "published" in Greek, that's why

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2017-11-23 20:30 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (338 votes). Check out past polls.