Reading Text

read, f, var1, var2, ..., varN reads the varI from file f
read, var1, var2, ..., varN reads the varI from keyboard
read_n, f, var1, var2, ..., varN read, skip non-numeric tokens
rdline(f) returns next line from file f
rdline(f, n) returns next n lines from file f
sread, s, var1, var2, ..., varN reads the varI from string s

The data type and dimensions of the varI determine how the text is converted as it is read. The varI may be arrays, provided the arrays have identical dimensions. If the varI have length L, then the read is applied as if called L times, with successive elements of each of the varI read on each call.

The read function takes the prompt keyword to set the prompt string, which defaults to "read> ".

Both read and sread accept the format keyword. The format is a string containing conversion specifiers for the varI. The number of conversion specifiers should match the number of varI. If the varI are arrays, the format string is applied repeatedly until the arrays are filled.

Read format strings in Yorick have (nearly) the same meaning as the format strings for the ANSI standard C library scanf routine. In brief, a format string consists of:

  • whitespace
    means to skip any number of whitespace characters in the source
  • characters other than whitespace and %
    must match characters in the source exactly or the read operation stops
  • conversion specifiers beginning with %
    each specifier ends with one of the characters d (decimal integer), i (decimal, octal, or hex integer), o (octal integer), x (hex integer), s (whitespace delimited string), any of e, f, or g (real), [xxx] to match the longest string of characters in the list, [^xxx] to match the longest string of characters not in the list, or % (the % character - not a conversion)