I think your problem is
- you have a large file
- you have created a new file with line endings removed
- now you want to read in characters between two positions in the new file
To do that you can use
sysseek and
sysread.
use Fcntl qw(SEEK_SET);
my $input = '...';
my $start = 1_490_117;
my $end = 1_492_312;
my $length = $end - $start +1;
open my $fh, '<', $input or die "Can't open $input: $!";
sysseek($fh, $start, SEEK_SET) or die "Can't seek to $start in $input:
+ $!";
my $sequence;
my $read = sysread $fh, $sequence, $length;
die "Failed to read $length bytes from $input, got $read"
if $length != $read;
Now
$sequence will contain the DNA sequence from 1,490,117 to 1,492,312 including both end points.
Note: sysread and sysseek use unbuffered IO, don't mix calls to them on a filehandle using other functions such as read, <> or eof.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.