in reply to How to swap rows with columns?
Aside from the modules and the compact solutions,
I'll try a non-obfuscated solution first ;-) This will
work on any 'text-matrix' as far as it's rectangular ...
mwa
I'll try a non-obfuscated solution first ;-) This will
work on any 'text-matrix' as far as it's rectangular ...
Regardsmy $inp=' 1 2 3 4 5 6 a b c x y z '; my @data; my @elem = grep length, split /\s+/, $inp; my $rows = () = $inp =~/(?<=^)\w/msg; my $cols = @elem / $rows; for my $col (0..$cols-1) { push @data, [ map $elem[$col + $cols*$_], 0..$rows-1 ] } # print the matrix print "@$_\n" for @data;
mwa
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How to swap rows with columns?
by FunkyMonk (Chancellor) on Oct 09, 2007 at 22:10 UTC |
In Section
Seekers of Perl Wisdom