Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Efficient regex search on array table

by sectokia (Pilgrim)
on Dec 15, 2022 at 02:35 UTC ( [id://11148879]=note: print w/replies, xml ) Need Help??


in reply to Efficient regex search on array table

Some suggestions:

Use Devel::NYTProf to actually benchmark properly and really see where your time is going.

Use the 'next' key word to go to the next item iteration in the loop when you know the row cannot match anymore, you don't need those rX counters. Example:

if ($regex1) { next if (( $accpyn1) && ($line1 =~ m/$regex1/)); next if ((!$accypn1) && ($line1 !~ m/$regex1/)); }

Replies are listed 'Best First'.
Re^2: Efficient regex search on array table
by Polyglot (Chaplain) on Dec 15, 2022 at 03:07 UTC
    I'm still puzzling over this suggestion. I understand the "next if" part well enough, but the dropping of my counters? I'm using the counters as part of the logic to tell me if the line has matched after all the columns have been checked (I don't know until then). It seems to my mind, and perhaps I am just slow of understanding, that the "next if" cannot be applied to all columns at once. Hence the counters.

    But if there were some way of adding the count at the same time as checking for a match, in one-liner fashion, that might be workable.

    Blessings,

    ~Polyglot~

Re^2: Efficient regex search on array table
by Polyglot (Chaplain) on Dec 19, 2022 at 01:49 UTC
    I'm responding again to this idea because your suggestion gained traction with me as I puzzled out a solution. I managed to eliminate the counters, as you suggested, and the code executes more efficiently now. Here's what that portion is now reduced to:
    next if ( ($regex1) && ( (($accpyn1) && ($line1 !~ m/$regex1/o)) || (!($accpyn1) && ($line1 =~ m/$regex1/o)) ) ); next if ( ($regex2) && ( (($accpyn2) && ($line2 !~ m/$regex2/o)) || (!($accpyn2) && ($line2 =~ m/$regex2/o)) ) ); next if ( ($regex3) && ( (($accpyn3) && ($line3 !~ m/$regex3/o)) || (!($accpyn3) && ($line3 =~ m/$regex3/o)) ) ); next if ( ($regex4) && ( (($accpyn4) && ($line4 !~ m/$regex4/o)) || (!($accpyn4) && ($line4 =~ m/$regex4/o)) ) );
    And with that logic, the counters became unnecessary. So thank you for the suggestion--it has been put to practical use.

    Blessings,

    ~Polyglot~

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-19 05:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found