Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Regex runs for too long

by Masem (Monsignor)
on Jan 23, 2002 at 23:40 UTC ( #140999=note: print w/ replies, xml ) Need Help??

in reply to Regex runs for too long

Do you *really* want to have a regex like that? I think the regex is the wrong solution. It's probably better to use split to get out the chucks of data and then decide what's important, for example:

while ( my $line = <FILE> ) { my @items = split "!CR!", $line; if ( expected ( @items ) ) { print join "\n", @items; } } # This would be need to be done to taste sub expected { my @data = @_; my $matched = 0; # Say you need to make sure the id line is there... foreach my $item ( @data ) { if ( $item =~ /^id\[\d+\]/ ) { $matched++; last } } return $matched; }
This solution I would suspect, regardless of how you write the matching routing, will be faster than the work you're trying to put on the regex engine, and this way would be much more understandable to other coders that might need it. If you need something more specific, tell us what you need to pull out from this text area and we can help more if needed.

Dr. Michael K. Neylon - || "You've left the lens cap of your mind on again, Pinky" - The Brain
"I can see my house from here!"
It's not what you know, but knowing how to find it if you don't know that's important

Comment on Re: Regex runs for too long
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2015-11-26 01:21 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (695 votes), past polls