Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Regex and question of design

by Random_Walk (Prior)
on Apr 14, 2005 at 09:42 UTC ( [id://447676]=note: print w/replies, xml ) Need Help??


in reply to Regex and question of design

If you have a few regex to apply to each line an array of pre-compiled regex is about the most optimimum you are going to get if you need to know which regex matched. If you only care about the fact one did match you could construct one super regex to rule them all but that could be dificult.

#!/usr/bin/perl use strict; use warnings; my @regex; while (<DATA>) { chomp; push @regex, qr/$_/; } while (my $line = <STDIN>) { for (0..$#regex) { print "matched no: $_\n" if $line=~/$regex[$_]/; } } __DATA__ foo bar baz

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

Replies are listed 'Best First'.
Re^2: Regex and question of design
by Anonymous Monk on Apr 14, 2005 at 11:31 UTC
    I've already quite the same script ;-)
    Thanks to remember me the existence of qr// !

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (1)
As of 2024-04-25 00:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found