Tutorials Point


  Perl Home

  PERL Functions

© 2011 TutorialsPoint.COM


  Home     References     About TP     Advertising  

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


Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names