Perl Programming/Keywords/read

From Wikibooks, open books for an open world
Jump to navigation Jump to search
Previous: rand Keywords Next: readdir

The read keyword[edit | edit source]

read is a function that attempts to read LENGTH characters of data into variable SCALAR from the specified FILEHANDLE. If OFFSET is specified, it skips the number of OFFSET characters. It returns the number of characters actually read. If the end of file is reached, 0 is returned. On an error undef is returned and $! is also set.

read is unfortunately not the opposite of write.

Syntax[edit | edit source]

  read FILEHANDLE, SCALAR, LENGTH, OFFSET
  read FILEHANDLE, SCALAR, LENGTH

See also[edit | edit source]

Previous: rand Keywords Next: readdir