Fixed length records: Difference between revisions

Content deleted Content added
Peak (talk | contribs)
jq
Line 339: Line 339:
goback.
goback.
end program unblocking.</lang>
end program unblocking.</lang>

=={{header|jq}}==

To read the raw input and write out raw strings, the command-line options -R (raw input), -s ("slurp"), and -r (raw output) options are necessary:

jq -Rrs -f program.jq infile.dat

program.jq:

To take advantage of tail-recursion optimization, we define an inner helper function, `c`, with arity 0:

<lang jq>def cut($n):
def c: if length==0 then empty else .[:$n] , (.[$n:] | c) end;
c;

cut(80) | explode | reverse | implode;</lang>



=={{header|Julia}}==
=={{header|Julia}}==
Line 357: Line 374:
processfixedlengthrecords("infile.dat", 80, "outfile.dat")
processfixedlengthrecords("infile.dat", 80, "outfile.dat")
</lang>
</lang>



=={{header|Go}}==
=={{header|Go}}==