Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: String to two dimensional array

by plobsing (Friar)
on May 07, 2008 at 08:13 UTC ( [id://685159]=note: print w/replies, xml ) Need Help??


in reply to String to two dimensional array

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); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://685159]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-19 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found