Multiplication tables: Difference between revisions

→‎{{header|Perl}}: Removed more magic numbers. Removed shebang line and "use strict", since they're implied. Switched to the statement-modifier form of "foreach" where possible, for readability.
(→‎{{header|Perl}}: Removed more magic numbers. Removed shebang line and "use strict", since they're implied. Switched to the statement-modifier form of "foreach" where possible, for readability.)
Line 224:
 
=={{header|Perl}}==
<lang perl>#!/usr/bin/perlour $max = 12;
our $width = length($max**2) + 1;
use strict;
our $max = 12;
 
printf "%${width}s", $_ foreach 'x|', 1..$max;
print " x|";
print "\n", '-' x ($width -- 1), '+"', "'-"' x ($max*4$width), "\n";
foreach my $a (1..$max) { printf(" %3d", $a); }
print "\n---+", "-" x ($max*4), "\n";
foreach my $i (1..$max) {
printf (" %2d${width}s", $i) ;_
foreach "$i|", map { $_ >= $i and $_*$i } 1..$max;
print "|";
foreach my $j (1..$max) {
if ($j >= $i) { printf(" %3d", $j*$i); }
else { print " "; }
}
print "\n";
}</lang>
 
Output:
 
<pre>
x| 1 2 3 4 5 6 7 8 9 10 11 12
845

edits