Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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 surveying the Monastery: (2)
As of 2018-03-21 05:45 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (263 votes). Check out past polls.