reads one newline-terminated line from a file or pipe
file descriptor or file name
The readline function attempts to read the next line from the specified file.
The readline function returns a string consisting of the line read from the file. The newline character at the end of the line is removed before returning the string.
If there are no more lines left to read, readline returns 0 instead of a string to indicate that the end of the file has been reached. If the file was specified as a file name, it is automatically closed at this point.
The call readline(default) reads a line from the current input stream. If readline(default) is typed at the top level, the next line typed will be read by readline instead of by the Maple parser. If readline is executed while file read is active, readline reads the next line of the file (the one following the call to readline).
The call readline(terminal) reads a line from the top level input stream. If Maple is being run interactively, any call to readline(terminal) will read a line from the user, even if a file read is in effect. If Maple is being run in batch mode (for example, using < for command line redirection) then readline(terminal) reads from the batch input file, even if a file read is in effect, since there is no user.
If a file name is given, and that file is not yet open, it is opened in READ mode with type TEXT.
The call readline(-1) is similar to readline(default), except that the Maple input preprocessor is invoked. Lines beginning with "!" are executed as operating system commands and lines beginning with "?" are translated as calls to the help function. Also, the readline(-1) command reads from the next prompt, while the readline(default) command opens a dialog for input.
For backwards compatibility, readline() is equivalent to readline(default).
The readline command is thread safe as of Maple 15.
Parallel calls to file i/o commands on the same file descriptor will be serialized in an arbitrary order. If you need the commands to execute in a particular order you must use Maple's synchronization tools to enforce this. See Threads:-Mutex.
For more information on thread safety, see index/threadsafe.
Get only the first and last lines of a file called "infile.text". NOTE: This example will only work if you have the "infile.text" file.
first ≔ readline⁡infile.text
line ≔ readline⁡infile.text
whileline≠0dolast ≔ line;line ≔ readline⁡infile.textend do
In the next example, the readline command is used to get input from the keyboard for a simple question: Guess a randomly generated integer between values 1 to 5.
GetNumber := proc()
number := rand( 1 .. 5 )();
printf( "Guess a number between 1 and 5:\n>> " );
while( parse( readline() ) <> number ) do
printf( "Try again!\n>> " );
printf( "Correct! The number was %d.\n", number );
Download Help Document
What kind of issue would you like to report? (Optional)