Just for fun, a solution using PDL:
use strict;
use warnings;
use PDL;
use PDL::Char;
my $str = "0 X X X X X X X X 1 X X X X X X X X 2 X X X X X X X X 3 X X
+ X X X X X X 4 X X X X X X X X 5 X X X X X X X X 6 X X X X X X X X 7"
+;
print pp_matrix( str2matrix($str, 8, 8) );
sub str2matrix {
# my ($str, $x, $y) = @_;
PDL::Char->new( shift )
->mslice([0,-1,2])
->reshape(1, shift, shift);
}
sub pp_matrix {
# my ($matrix) = @_;
shift ->reshape(-1)
->append( PDL::Char->new("\n") )
->flat
->atstr(0);
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.