in reply to generating rows(matrix) based on file content
Here a version if the number of switches is not known upfront.
use strict; use warnings; my $max = 0; my $data; while(<DATA>){ chomp; my @array = split /\s/; my @line = ( shift @array ); $line[$_] = 1 for @array; $max = @line > $max ? @line : $max; push @$data, \@line; } for my $row (@$data) { print $row->[$_]//0 ," " for (0..$max-1); print "\n"; } __DATA__ run1 2 4 run2 1 6 run3 1 run4 1 3 run5 2 5
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: generating rows(matrix) based on file content
by hdb (Monsignor) on Apr 23, 2013 at 20:41 UTC |