more useful options | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
It seems to me your code is doing nothing more than printing out the input with newlines removed. You can achieve the same result by removing all newlines with: $map =~ y/\n//r; For me this took a few seconds on a 2GiB + 16 byte string (whereas creating the same string with the repetition operator took more than twice as long, and that was without any IO). Your approach with split runs out of memory on my 4GiB VM, because split generates a new list with new strings, more than doubling the memory requirement (depending on density of newlines). I strongly suspect, however, that even if it worked, the split would be much slower. I also wonder if this may be an XY Problem: You say the read cannot be changed, and try as I might, I can't imagine why you'd want to read a huge binary file and print out everything but the newlines. If my advice doesn't hit the mark, can you give us a few more details on what it is you're doing? open (INFILE, "$FILE") || die "Not able to open the file: $FILE \n"; Be careful with open. If you ever intend $FILE to be user-specified (and even if you don't), I'd recommend using the 3-argument open: open INFILE, '<', $FILE or die "Not able..."; See Two-arg open() considered dangerous. I'd also use a lexical filehandle (open my $infile, ...) instead of INFILE. In reply to Re: Parse string greater than 2GB
by rjt
|
|