Fixed length records: Difference between revisions

(Fixed length records en FreeBASIC)
Line 1,221:
and
[https://github.com/SqrtNegInf/Rosettacode-Perl5-Smoke/blob/master/ref/flr-outfile.dat output file]
===There Is More Than One Way To Do It===
Read with standard <> using $/ set to a ref-to-int to read a fixed block size.
<lang perl>{
local ($/, @ARGV) = (\80, 'infile.dat');
open my $out, '>', 'outfile.dat' or die $!;
print $out scalar reverse while <>; # can read fixed length too :)
close $out;
}</lang>
Slurp and reverse each line in place.
<lang perl>use Path::Tiny;
path('outfile.dat')->spew(path('infile.dat')->slurp =~ s/.{80}/reverse $&/gesr);</lang>
Double reverse.
<lang perl>use Path::Tiny;
path('outfile.dat')->spew(reverse unpack '(a80)*', reverse path('infile.dat')->slurp);
</lang>
Bonus round: convert the sample file to Forth Block format.
<lang perl>use Path::Tiny;
path('outfile.dat')->spew(pack '(A64)16', split /\n/, path('sample.txt')->slurp);</lang>
Bonus Round: convert Forth Block format to plain text format.
<lang perl>use Path::Tiny;
path('sample2.txt')->spew(map "$_\n", unpack '(A64)16', path('outfile.dat')->slurp);</lang>
 
=={{header|Phix}}==
Anonymous user