in reply to Vertical number representation for Turing Machine tape display?

Without using format you could:

use strict; use warnings; my $tape = bless { desc => "5-state machine, theoretical max steps: >47,176,870", step => 630, delta => 54, pos => 224, cells => [], }; push @{$tape->{cells}}, int rand (1.7) || ' ' for 1 .. 500; $tape->show (82); print <<ORG; 5-state machine, theoretical max steps: >47,176,870 Step: 630 Current delta: 54 ---------------------------------------------------------------------- +----------­- 1 2 + 2 8 9 0 1 2 3 4 5 + 6 6 4567890123456789012345678901234567890123456789001234567890123456789012 +345678901234 ----------------------------------------v----------------------------- +----------­- 1 11 1 1 1 11 111 1 + 11 ORG sub show { my ($tape, $width) = @_; my $first = int ($tape->{pos} - $width / 2); my $last = $first + $width - 1; my $mag = int (log ($last) / log (10)) + 1; my $divider = '-' x $width; $first = sprintf '%0*d', $mag, $first; $last = sprintf '%0*d', $mag, $last; printf "%66s\n", $tape->{desc}; print "Step: $tape->{step}\n"; print "Current delta: $tape->{delta}\n"; print $divider, "\n"; for my $digit (0 .. $mag - 1) { my $lastDigit = -1; my $row; for my $num ($first .. $last) { my $newDigit = substr sprintf ("%${mag}d", $num), $digit, +1; $row .= $num != $last && $newDigit eq $lastDigit ? ' ' : $ +newDigit; $lastDigit = $newDigit; } print "$row\n"; } substr $divider, $width / 2, 1, 'v'; print $divider, "\n"; print @{$tape->{cells}}[$first .. $last], "\n"; }

Prints:

5-state machine, theoretical max steps: >47,176,870 Step: 630 Current delta: 54 ---------------------------------------------------------------------- +------------ 1 2 + 2 8 9 0 1 2 3 4 5 + 6 6 3456789012345678901234567890123456789012345678901234567890123456789012 +345678901234 -----------------------------------------v---------------------------- +------------ 11 1 1 1 1 1 1 1 11 11 1 111 11 1 11 11 1 1 + 111 1 11 5-state machine, theoretical max steps: >47,176,870 Step: 630 Current delta: 54 ---------------------------------------------------------------------- +----------­- 1 2 + 2 8 9 0 1 2 3 4 5 + 6 6 4567890123456789012345678901234567890123456789001234567890123456789012 +345678901234 ----------------------------------------v----------------------------- +----------­- 1 11 1 1 1 11 111 1 + 11

Perl reduces RSI - it saves typing