Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: text file problem

by hipowls (Curate)
on May 10, 2008 at 21:02 UTC ( #685909=note: print w/ replies, xml ) Need Help??


in reply to text file problem

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.


Comment on Re: text file problem
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2014-12-22 08:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (113 votes), past polls