Selective file copy: Difference between revisions

algol 68 sample added
(→‎{{header|Fortran}}: More details...)
(algol 68 sample added)
Line 6:
<br>The ''by name'' assignment is a little extra available in PL/I.
<br>Data conversions may be necessary (as shown here for data element ''c'' in the Go listing).
 
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
Using formatted transput to process similar files to the COBOL sample.
<lang algol68>MODE INPUTRECORD = STRUCT( STRING field a, STRING field b, INT field c, CHAR sign of field c, STRING field d );
MODE OUTPUTRECORD = STRUCT( STRING field a, INT field c, STRING field x );
 
FORMAT input format = $ 5a, 5a, 4d, 1a, 5a l $;
FORMAT output format = $ 5a, 3z-d, 5a l $;
 
IF FILE input file;
STRING file name = "input.txt";
open( input file, file name, stand in channel ) /= 0
THEN
# failed to open the file #
print( ( "Unable to open """ + file name + """", newline ) )
ELSE
# file opened OK #
BOOL at eof := FALSE;
# set the EOF handler for the file #
on logical file end( input file, ( REF FILE f )BOOL:
BEGIN
# note that we reached EOF on the #
# latest read #
at eof := TRUE;
# return TRUE so processing can continue #
TRUE
END
);
WHILE INPUTRECORD in record;
getf( input file, ( input format, in record ) );
NOT at eof
DO
IF sign of field c OF in record = "-" THEN field c OF in record *:= -1 FI;
OUTPUTRECORD out record;
field a OF out record := field a OF in record;
field c OF out record := field c OF in record;
field x OF out record := "XXXXX";
putf( stand out, ( output format, out record ) )
OD;
# close the file #
close( input file )
FI</lang>
 
Input file:
<pre>
A bbbbB0001+d2345
AA bbbBB0002+1d345
AAA bbBBB0003+12d45
AAAA bBBBB0001-123d5
AAAAABBBBB0002-1234d
</pre>
{{out}}
<pre>
A 1XXXXX
AA 2XXXXX
AAA 3XXXXX
AAAA -1XXXXX
AAAAA -2XXXXX
</pre>
 
=={{header|COBOL}}==
3,038

edits