my @pids; { open(my $pids_fh, '<', $pids_qfn) or die("Can't open PIDS file \"$pids_qfn\": $!\n"); push @pids, /\|(\d+)$/ while <$pids_fh>; } my $pids_pat = map qr/$_/, join '|', #map quotemeta, # We're only dealing with digits @pids; open(my $fids_fh, '<', $fids_qfn) or die("Can't open FIDS file \"$fids_qfn\": $!\n"); while (<$fids_fh>) { print if /^$pids_pat;/; }
If you need extra speed and your Perl is older than 5.10, change
tomy $pids_pat = map qr/$_/, join '|', #map quotemeta, # We're only dealing with digits @pids;
use Regexp::List qw( ); my $pids_pat = Regexp::List->new()->list2re(@pids);
5.10 already does the optimisation Regexp::List does.
In reply to Re^3: My code sucks, please help me understand why. (regex)
by ikegami
in thread My code sucks, please help me understand why.
by mirage4d
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |