I actually thing the InflateColumn approach is best because it will DWIM most of the time. I *think* the only problem in this case is you're purposefully fetching everything on every pass. There's no need-

foreach my $watch_string ( $schema->resultset('WatchString')->all +) # Could be... my $ws = $schema->resultset('WatchString') ->search({}, { cache => 1 }); while( my $line <INPUT> ) { foreach my $watch_string ( $ws->all )

Untested, but as far as I know, it should work. It probably won't be the greatest optimization possible, that would probably involve dispensing with objects and inflating to hashrefs and doing the regex inflation, once, in place in the raw data. That might look like-

my $ws = $schema->resultset('WatchString'); $ws->result_class('DBIx::Class::ResultClass::HashRefInflator'); my @ws = $ws->all; $_->{match_string} = qr/$_->{match_string}/ for @ws; while( my $line <INPUT> ) { foreach my $ws ( @ws ) { if( $line =~ $ws->{match_re} ) # all hashrefs now, no objects. {

I'm less certain of that code but it should be close if not correct.


In reply to Re: How to cache a regular expression in a DBIx::Class object by Your Mother
in thread How to cache a regular expression in a DBIx::Class object by chrestomanci

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.