Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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

by oiskuu (Friar)
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2015-07-08 03:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (94 votes), past polls