cormanaz has asked for the wisdom of the Perl Monks concerning the following question:
or using option 2:my @kwlist = qw(foo bar baz qux); my $kwre = join('|',@kwlist); my @items = getfromdb("select id,text from table"); # I have a sub tha +t does this foreach my $i (0..$#items) { my ($id,$text) = @{$items[$i]}; my $count = 0; while($text =~ /$kwre/g) { $count++; } }
Or is there some faster way to do it I haven't thought of? I have no idea what is going on under the hood in these two options that would affect execution time but I feel confident some other monks do.use JSON::XS; my @kwlist = qw(foo bar baz qux); my @items = getfromdb("select id,keywordhash from table"); # I have a +sub that does this foreach my $i (0..$#items) { my ($id,$temp) = @{$items[$i]}; my $kws = decode_json($temp); my $count = 0; foreach my $k (@kwlist) { if (defined($kws->{$k})) { $count++; } } }
BTW I realize there may be some way to do it with an exotic postgres query, but it's beyond me and anyway the list of keywords I'm looking for is rather long so it would be unwieldy.
|
---|