Reading from Files
read (FILE, $var, 1024); #reading in block size
write(FILE, $var, 1024);
This works fantastically when dealing with binary files so that fetching and writing is fast and efficient.
Perl provides another set of functions
$written = syswrite(DATAFILE, $mystring, length($mystring));
die "syswrite failed: $!\n" unless $written == length($mystring);
$read = sysread(INFILE, $block, 256, 5);
warn "only read $read bytes, not 256" if 256 != $read;
The syswrite call sends the contents of $mystring to DATAFILE. The sysread call reads 256 bytes from INFILE and stores them 5 characters into $block, leaving its first 5 characters intact.
$var = "Header: ";
$cnt = sysread(FILE,$var, 10, length($var));
Here the read content is placted at the end of variable
10 specifies no of characters to be read,
length($var) specifies where ithe fetched contents are to be placed in output buffer.