Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by wazat (Monk)
on Nov 04, 2017 at 18:56 UTC ( [id://1202763]=note: print w/replies, xml ) Need Help??


in reply to Faster and more efficient way to read a file vertically

OOPS, I see that yr already identified this approach.

If your lines are really all the same length, you could do the job via a seek() / read() loop. The example below needs error checking. I haven't done any speed tests.

#!/usr/bin/perl use strict; use warnings; my $linesep_len = length($/); my $rec_len = length('ACATCACCTCCCACAACGAGGACTACACCATCGTGGAACA') + $li +nesep_len; my $read_len = 1; my $skip_len = $rec_len - $read_len; binmode(DATA); seek(DATA, 10, 1) or die "seek error"; my $buf = ' ' x $read_len; while (read(DATA, $buf, $read_len) > 0) { print $buf, "\n"; seek(DATA, $skip_len, 1) or last; } __DATA__ ACATCACCTCCCACAACGAGGACTACACCATCGTGGAACA ACATCACCTCxCACAACGAGGACTACACCATCGTGGAACA ACATCACCTCsCACAACGAGGACTACACCATCGTGGAACA ACATCACCTCjCACAACGAGGACTACACCATCGTGGAACA ACATCACCTCcCACAACGAGGACTACACCATCGTGGAACA ACATCACCTCCCACAACGAGGACTACACCATCGTGGAACA ACATCACCTCCCACAACGAGGACTACACCATCGTGGAACA ACATCACCTCCCACAACGAGGACTACACCATCGTGGAACA ACATCACCTCCCACAACGAGGACTACACCATCGTGGAACA ACATCACCTC-CACAACGAGGACTACACCATCGTGGAACA
Output:
C x s j c C C C C -

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1202763]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-18 06:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found