Rexx - Lines


Advertisements

This function returns either the value 1 or the number of lines left to read in an input stream. The filename is given as the input to the function.

Syntax

lines(filename)  

Parameters

  • filename − This is the name of the file.

Return Value

This function returns either the value 1 or the number of lines left to read in an input stream.

Example

/* Main program */ 
do while lines(Example.txt) > 0 
   line_str = linein(Example.txt) 
   say line_str 
end  

In the above program the following things need to be noted.

  • The lines function reads the Example.txt file.

  • The while function is used to check if further lines exist in the Example.txt file.

  • For each line read from the file, the line_str variable holds the value of the current line. This is then sent to the console as output.

Output − When we run the above program, we will get the following result.

Example1 
Example2 
Example3

There is another variation of the lines command which is as follows −

Syntax

lines(filename,C)

Parameters

  • filename − This is the name of the file.

  • C − This is a constant value provided to the function. This value which specifies the number of lines left to read from the file.

Return Value

The return value is the count of lines that are left to be read from the file.

Example

/* Main program */ 
count = lines(Example.txt,C) 
say count 
line_str = linein(Example.txt) 

say line_str 
count = lines(Example.txt,C) 
say count 

When we run the above program we will get the following result.

Output

3 
Example1 
2 
rexx_functions_for_files.htm
Advertisements