From 185f4a02d819fb219547ba16caab2a64c337c974 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Tue, 4 Feb 2025 15:32:55 -0800 Subject: [PATCH] Add examples to documentation for `sysread()` --- pod/perlfunc.pod | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 1f4fec705677..4893f1e98ce5 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -9572,6 +9572,17 @@ the string. A positive OFFSET greater than the length of SCALAR results in the string being padded to the required size with C<"\0"> bytes before the result of the read is appended. + open(my $FH, "<", "input.txt") or die("Cannot open file: $!"); + + my $buf = ""; + my $num = 0; + + # Read up to 64 bytes + $num = sysread($FH, $buf, 64); + + # Read up to 32 bytes into position 512 of $buf + $num = sysread($FH, $buf, 32, 512); + There is no syseof() function, which is ok, since L|/eof FILEHANDLE> doesn't work well on device files (like ttys) anyway. Use L|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> and