Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://140999]
and all is quiet...

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

    Results (343 votes). Check out past polls.