3.02 Stream Output

Overview

Stream output is carried out using the PUT command.

PUT

Function:

Writes the expression to the target as a stream of data.

Syntax:

PUT [target,] [USING [string],]
    [AT([row,] col)] expression[, expression] [:] ...
PUT [target,] [USING [string],] DATA {label|delimiter}
Possible values for target are:
STDOUT/SYSOUT (default value)
STDERR/SYSERR/ERROR
CONSOLE
FILE file

The expression is any valid LynPlex expression.

By default the PUT command always ends with a new line character, whether the output is to a file or a console.

The new line can be suppressed if the expression end with the concatenation operator (:) followed by either the shift left operator (<<) or the shift right operator (<<). In this case the next PUT statement will continue from this point.

The default output destination can be changed during execution using the OPTION statement.

The AT option is only used for console output. See AT.

USING Option

When USING is specified, the string template is used to format numbers and strings. The first expression in the PUT statement is assigned to the first target in the format, the second to the second and so on.

Once a formatting string has been specified it is kept as the current formatting string until a new string is provided in a subsequent statement. To use the same formatting string just enter USING in a PUT statement without a new string. PUT will use the format from the previous call.

It is also possible to format an expression using the FORMAT Function.

For more information see Formatting Syntax below.

Comma Separator

A comma may be entered anywhere between expressions. Whenever a comma is encountered it will be written to the output stream as a comma followed by a space. This enables a file to be written in comma separated value (CSV) format.

Concatenation

The concatenation rules are the same as for expressions in general. See Concatenation in 1.03 Language Overview.

Where the concatenation operator (:) is specified at the end of the statement, followed by either the shift left operator (<<) or the shift right operator (<<) no end of line marker in the form of a carriage return/line feed combination is sent. In this case the next PUT statement will continue writing from this point.

FORMAT Function

Function:

Returns a formatted string. Syntax:

FORMAT(format, value[, value] ...) 

Formatting Syntax

The following characters are allowed in the formatting string:

Numbers:
#
Digit or space
0
Digit or zero
^
Stores a number in exponential format.
.
The position of the decimal point.
,
Separator.
-
Stores minus if the number is negative.
+
Stores the sign of the number.
Strings:
&
Stores a string expression without reformatting it.
!
Stores only the first character of a string expression.
\ \
Stores the first n + 2 characters of a string expression, where n is the number of spaces between the two backslashes. There can be literals inside the \ \ that are inserted into the final string.
Escape:
_
Print next character as a literal. The combination _#, for example, allows you to include a hash sign as a literal in your numeric format.
Other:
[other]
Other characters may be included as literals in the format string.

Example:

put using "##: #,###,##0.00":
for ix = 1 to 10
  put using, ix, random * 10000
  next
...
put using  "Total ###,##0 \ \", 76, "trombones"
...
put format("#,##0", 1920.6)   // displays 1,921
...
put format("\  - \", "abcde") // displays "abc-de"

DATA

The data option is used to write the series of lines from the specified label to the delimiter marking the end of the data.

The data lines may contain anything that is valid in a data statement other than using or data itself. Each line will be processed as if it had been entered directly on the put statement.

When data is specified no other option may be specified in the put statement.

See 3.09 Instream Data for more information.


lynplex/lp0302.txt · Last modified: 2012/06/25 14:58 (external edit)