Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^6: Bolt on where a match is not found to a print script

by AnomalousMonk (Archbishop)
on Dec 06, 2017 at 17:27 UTC ( [id://1205034]=note: print w/replies, xml ) Need Help??


in reply to Re^5: Bolt on where a match is not found to a print script
in thread Bolt on where a match is not found to a print script

What Anonymous Monk said:

while (my ($match) = m/$regex/g) { $matched{$match} = 1; print "$file $_"; }
gives you an infinite loop.
c:\@Work\Perl\monks>perl -wMstrict -le "my $regex = qr{ \b f[eio]e \b }xms; ;; $_ = 'xx fee fie foe yy'; while (m/($regex)/g) { my $match = $1; print qq{captured '$match'}; } " captured 'fee' captured 'fie' captured 'foe'
works better (at least it stops). If you want to get a bit fancy,
while (m/($regex)/g and my $match = $1) { print qq{captured '$match'}; }
also works. But the whole "extract multiple matches per line" thing may not even be a real issue! The OPer says nothing about it, and I only raised it as a cautionary point of interest.


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-24 03:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found