Hi, Monks,
I have a file with 861_600 lines of text. I wish to find the earliest line that exactly matches any of a small set of strings. Here's part of my current code:
use List::Util 'first';
use File::Map 'map_handle';
open my $fh, '<', 'huge_file';
map_handle my $map, $fh;
my $string = first {$_ ~~ @strings} ($map =~ m"^(.*)$"gm);
Does this stop searching on the first match? If not, would the following stop searching on the first match?
use List::MoreUtils 'firstval';
use File::Map 'map_handle';
open my $fh, '<', 'huge_file';
map_handle my $map, $fh;
my $string = firstval {$_ ~~ @strings} ($map =~ m"^(.*)$"gm);
If not, would anything stop searching on the first match? Any other advice for how to speed up this code would be much appreciated.
$_="msh210";$"=$\;@_=@{[split//,uc]}[2,0];$_="@_$\1";$\=$/;++$_[0]for$...1;print lc substr crypt($_,"@_"),1,6
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.