Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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 - mneylon-pm@masemware.com || "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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2014-09-21 18:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (173 votes), past polls