in reply to About text file parsing
See if it is faster reading big chunks at a time, like this simple test case (of course, modify it for your file).
This only runs the regexes once for each chunk, instead of once per line.
#!/usr/bin/perl # https://perlmonks.org/?node_id=1221282 open my $fh, '<', \<<END; ###### test.txt######## sample AA sample BB Not sample CC good boy good yyy bad aaa END local $/ = \1e6; # or bigger chunk depending on your memory size while(<$fh>) # read big chunk { $_ .= do { local $/ = "\n"; <$fh> // ''}; # read any partial line push @sample, /^sample\s+(\S+)/gm; push @good, /^good\s+(\S+)/gm; } close($fh); print "sample = @sample\n good = @good\n";
Outputs:
sample = AA BB good = boy yyy
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: About text file parsing
by marioroy (Prior) on Aug 30, 2018 at 20:52 UTC |