in reply to Faster and more efficient way to read a file vertically
If "same length", then straightforward and perhaps not perlish, and idea originated before Discipulus's answer :). I wonder how inefficient this is compared to slurping/reading in large blocks, i.e. if read and seek 'cooperate' on input buffer (I don't know enough on underlying C calls).
use strict; use warnings; use autodie; my $POS = 10; open my $fh, '<', 'dna.txt'; my $L = length( <$fh> ) - 1; seek $fh, $POS - 1, 0; my ( $s, $i ) = ( '', 0 ); seek $fh, $L, 1 while read $fh, $s, 1, $i++; print "$s\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Faster and more efficient way to read a file vertically
by ForgotPasswordAgain (Vicar) on Nov 03, 2017 at 20:58 UTC | |
by ForgotPasswordAgain (Vicar) on Nov 03, 2017 at 21:12 UTC |