149

Input/Output
Input in Scalar Context

  • To read one line at a time from an input stream, enclose the file handle in < > simbols and assign the result to a scalar variable

      $line = <FILEHANDLE>;

  • Given the input

      Hello
      World

  • One line can be read at at time as follows

      $line = <FILEHANDLE>; # Yields "Hello\n"
      $line = <FILEHANDLE>; # Yields "World\n"

  • To read the entire contents of an input, this scalar read can be placed in a loop