1. Perl
  2. builtin functions
  3. here

syswrite function - write to file with a specified number of bytes (no buffering)

You can use the syswrite function to write a specified number of bytes to a file.

syswrite $fh, $buffer, $byte_size;

The first argument is the file handle, the second argument is the scalar variable that is the data to write, and the third argument is the byte size.

When the syswrite function is executed, the data of the specified byte size is written to the file handle specified by the first argument.

The syswrite function does not buffer and writes immediately. The syswrite function is paired with sysread function.

For a detailed explanation of the syswrite function, refer to the official documentation.

Example syswrite function

This is an example program of the syswrite function. The syswrite function is used to write the length of the string.

use strict;
use warnings;

# Open the file to write
my $file = 'data.txt';
open my $fh, '>', $file
  or die "Can't open file $file:$!";

# syswrite function
my $buffer = 'AGTC';
my $byte_size = length $buffer;
syswrite $fh, $buffer, $byte_size;

Related Informatrion