in reply to Transpose a matrix of chars

#! perl -slw use strict; use List::Util qw[ max ]; use Data::Dumper::SLC; my @cmat = ( [ qw[ A B C F G ] ], [ qw[ u b ] ], [ qw[ 1 T A R S 2 P] ], ); my @trans = map { my $index = $_; [ map{ $_->[ $index ] } @cmat ]; } 0 .. max map{ $#$_ } @cmat; Dump \@trans; __END__ P:\test>junk [ [ 'A', 'u', '1', ], [ 'B', 'b', 'T', ], [ 'C', undef, 'A', ], [ 'F', undef, 'R', ], [ 'G', undef, 'S', ], [ undef, undef, '2', ], [ undef, undef, 'P', ], ]

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Replies are listed 'Best First'.
Re^2: Transpose a matrix of chars
by ysth (Canon) on Jul 04, 2005 at 22:45 UTC
    Data::Dumper::SLC ?? What's that?

    And were you intentionally ignoring the request that modules not be used? I don't have a problem with that, but usually people say something like "modules are part of my toolkit, like it or lump it" or something more polite.

      Data::Dumper::SLC ?? What's that?

      It's my own module that produces better formatted output than Data::Dumper. As it is only used to test that the tranformation is correct, it doesn't affect the OPs use of the algorithm demonstrated.

      And were you intentionally ignoring the request that modules not be used?

      That leaves only my use of List::Util::max. Which, as it has been a part of the core for a while now, the possibility is that the OP would have access to it without an additional installation. If not, then the OP only has to ask here how write an equivalent function, or read the source of the pure perl version of L::U, if they don't know how to do that already.

      Feel free to consider the node for removal if this explaination doesn't satisfy.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
        Feel free to consider the node for removal if this explaination doesn't satisfy.
        ?? Sorry, I wasn't trying to complain (though rereading my note, it certainly sounds like a complaint). I was honestly curious whether you were intentionally or unintentionally using modules. If I hadn't had the question about DDSLC I wouldn't have even bothered posting.

        Let me try again:

        I see you are using some modules though the OP is looking for a solution that doesn't do so. More power to your elbow! A perl programmer without modules is like a shell programmer without a keyboard! (Well, not quite.) But did you miss that part of the OP? Or just ignore it but not want to bring up the same old discussion that comes up whenever anybody claims they "aren't allowed to use modules"? Or other?