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

In reply to Re: Vertical number representation for Turing Machine tape display? by GrandFather
in thread Vertical number representation for Turing Machine tape display? by eric.foxx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.