Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Faster and more efficient way to read a file vertically

by BrowserUk (Pope)
on Nov 03, 2017 at 20:12 UTC ( #1202721=note: print w/replies, xml ) Need Help??


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

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1202721]
help
Chatterbox?
[choroba]: Monopoli looks nice, but a bit far from here.
[1nickt]: Morning monks, howzit?

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2018-01-23 13:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (246 votes). Check out past polls.

    Notices?