in reply to A vertical (+/- random) split of a file

I have here a little thing called swap_row_col.pl. It's very old (my filesystem says I haven't touched it in more than 4 years) so I just refactored it now. Once swapped in this way, the data can be List::Util::shuffle'd and swap_row_col'ed again. This is tested:

use warnings; use strict; use List::Util qw/shuffle/; sub swap_row_col { my @swapped; foreach (@_) { chomp; ## just in case my @elems = split /;/; for (my $i = 0; $i < @elems; $i++) { exists $swapped[$i] and $swapped[$i] .= ';'; $swapped[$i] .= $elems[$i]; } } return @swapped; } my @vshuffled = swap_row_col shuffle swap_row_col <DATA>; __DATA__ one;two;three;four foo;bar;baz;qux yellow;red;blue;green

The output from Data::Dumper is something like this:

$VAR1 = [ 'one;three;four;two', 'foo;baz;qux;bar', 'yellow;blue;green;red' ];

--
David Serrano

Replies are listed 'Best First'.
Re^2: A vertical (+/- random) split of a file
by Marsel (Sexton) on Jul 21, 2006 at 20:32 UTC
    That's great,
    of course like that, you don't have to open and close output files at each line (which will save time, won't it ?).

    Thanks !

    marsel