To keep this problem from happening again, you might want to look at Quantum::Superpositions, specifically the any() and all() functions.Eh, no, you don't. Quantum::Superpositions is extremely slow. There's no justification for using Quantum::Superpositions, just to save typing a pair of parenthesis. Here's a benchmark:
#!/usr/bin/perl use strict; use warnings; use Benchmark qw /cmpthese/; use Quantum::Superpositions; our @data1 = "aa" .. "zz"; our @data2 = "AA" .. "ZZ"; my %queries = ( middle => [$data1 [@data1 / 2], $data2 [@data2 / 2]], first => [$data1 [0], $data2 [0]], not => ["feeble", "fnord"], ); foreach my $type (qw /middle first not/) { warn "Running '$type' test.\n"; our ($q1, $q2) = @{$queries {$type}}; our ($a_g, $a_q); cmpthese -1 => { grep => '$a_g = grep ({$q1 eq $_} @data1) && grep ({$q2 eq $_} @data2)', QS => '$a_q = $q1 eq any (@data1) && $q2 eq any (@data2)' +, }; die "Unequal" if $a_g xor $a_q; print "\n"; } __END__ Running 'middle' test. Rate QS grep QS 24.5/s -- -99% grep 2376/s 9588% -- Running 'first' test. Rate QS grep QS 24.1/s -- -99% grep 2400/s 9869% -- Running 'not' test. Rate QS grep QS 48.6/s -- -99% grep 5744/s 11719% --
Abigail
In reply to Re: multiple greps at once-- possible?
by Abigail-II
in thread multiple greps at once-- possible?
by sulfericacid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |