What is the most convenient way to extract the specified byte range of a file on disk into a variable?
seek before the start of the read range the desired number of bytes (or sysseek / sysread - see nohat comment).
seek
read
sysseek
sysread
open $fh, '<', $filename; seek $fh, $startByte, 0; $numRead = read $fh, $buffer, $endByte - $startByte; # + 1 &do_something_with($buffer);
Sometimes I like to use File :: Map , which lazily loads the file into a scalar. This turns it into string operations instead of file descriptor operations:
use File::Map 'map_file'; map_file my $map, $filename; my $range = substr( $map, $start, $length );
Source: https://habr.com/ru/post/1307178/More articles:Scheduled task to open URL - scheduled-tasksStop python script execution if parent Bash shell script is killed - pythonFrom inside xslt, can you output all the XML? - c #How to get your own IP address? - urlJSON implementations that process sparse arrays - jsonIn Scala, how do I write a class with a constructor, and not all of whose arguments are members of the class? - constructorHow to represent a sparse array in JSON? - jsonUIImageJPEGRepresentation - memory issue issue - memoryLocation view.properties in my spring mvc jasperreports project - javaMSDN An example of handling an exception from a TPL is a race condition? - c #All Articles