Logo

Programming-Idioms

  • Perl
  • Pascal

Idiom #278 Read one line from the standard input

Read one line into the string line.

Explain what happens if EOF is reached.

$line = <STDIN>;

The < > operator evaluates a filehandle, in this case the built-in filehandle STDIN, which in turn reads a line and returns it. $line contains its trailing newline, if it was present. If EOF is reached, the undefined value (undef) is returned. Perl treats undef as false when tested in a condition.
readln(line);

processing reading the inputs stops when EOF is reached.
with Ada.Text_IO;
Line : constant String := Ada.Text_IO.Get_Line;

End_Error is raised if EOF is reached.

New implementation...
< >
programming-idioms.org