This, unfortunately, doesn’t work:
my $input = "this is a test";
open(my $fh, "<", \$input);
my $n = sysread($fh, $buf, 4); # want $n == 4, $buf eq 'this'
Replacing sysread with read works as expected.
Is this expected? Could it be made to work? Am I missing something?
After sysread, does the variable $! contain “Bad file descriptor”? Then you may have encountered bug 72428 “sysread does not work on a filehandle to a scalar” ( https://rt.perl.org/rt3/Public/Bug/Display.html?id=72428 )