Copyright © tutorialspoint.com

PERL read Function


Syntax

read FILEHANDLE, SCALAR, LENGTH, OFFSET

read FILEHANDLE, SCALAR, LENGTH


Definition and Usage

Reads, or attempts to read, LENGTH number of bytes from the file associated with FILEHANDLE into BUFFER. If an offset is specified, the bytes that are read are placed into the buffer starting at the specified offset.

Return Value

  • The number of bytes read or the undefined value.

Example

Try out following example:

#!/usr/bin/perl -w

my($buffer) = "";
open(FILE, "/etc/services") or
     die("Error reading file, stopped");
while(read(FILE, $buffer, 100) )
{
   print("$buffer\n");
}
close(FILE);

It will produce following result. This is just sanpshot of the result

kerberos_master 751/udp  # Kerberos authentication
kerberos_master 751/tcp  # Kerberos authenti
cation
passwd_server   752/udp  # Kerberos passwd server

Copyright © tutorialspoint.com