in reply to Regex: Capturing and optionally replacing
Forget about doing everything in one regexp. It just makes it hard to read and hard to maintain.
while (<DATA>) { chomp; my ($host, $domain, $test) = /^([^,]+),([^.]+)\.(.+)$/; next if not defined $host; $domain =~ s/,/./g; next if substr($domain, -4) eq '.net'; print("Host: $host Test: $test\n"); }
Update: This should be faster:
while (<DATA>) { print("Host: $1 Test: $2\n") if /^([^,]+),[^.]+(?<!,net)\.(.+)$/; }
Update: I just realized you said it needs to process 6000 files a minute. That's 100 files a second! That seems excessive. You way want to rethink your design.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex: Capturing and optionally replacing
by McDarren (Abbot) on Dec 08, 2005 at 16:11 UTC | |
by ikegami (Patriarch) on Dec 08, 2005 at 16:37 UTC | |
by McDarren (Abbot) on Dec 08, 2005 at 17:13 UTC | |
by McDarren (Abbot) on Dec 09, 2005 at 00:34 UTC | |
by ikegami (Patriarch) on Dec 09, 2005 at 06:18 UTC |