Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Out of Memory - Line of TXT too large (mmap)

by oiskuu (Hermit)
on Jan 02, 2014 at 15:45 UTC ( #1068977=note: print w/ replies, xml ) Need Help??

in reply to Out of Memory - Line of TXT too large

Scan a very big file, working on some portions? This a good opportunity for mmap. For example:

use File::Map ':all'; my $file = shift; my $SEP = "\n"; # line/chunk separator my ($s, $e); open(my $fh, '<', $file) || die "$!"; map_handle(my $mmap, $fh, '<'); sub process {} for ($e = 0;; $e += length($SEP)) { ($s, $e) = ($e, index($mmap, $SEP, $e)); print "fragment [$s, $e)\n"; process($e < 0 ? substr($mmap, $s) : substr($mmap, $s, $e-$s)); last if $e < 0; }

Comment on Re: Out of Memory - Line of TXT too large (mmap)
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2016-02-09 01:55 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (296 votes), past polls