in reply to Faster and more efficient way to read a file vertically
If you make an array of substr references to the characters in a buffer, and then overlay each line into that buffer, the cost of performing the splitting/indexing of the strings is done once:
#! perl -slw use strict; my $c = $ARGV[ 0 ] // 25; my $buf = chr(0) x 62; my @cRefs = map \substr( $buf, $_, 1 ), 0 .. length( $buf )-1; until( eof( DATA ) ) { substr( $buf, 0 ) = <DATA>; print ${ $cRefs[ $c ] }; } __DATA__ ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz
A few runs:
C:\test>1202693 0 A A A A C:\test>1202693 25 Z Z Z Z C:\test>1202693 32 6 6 6 6 C:\test>1202693 61 z z z z
|
|---|