07/05/26 04:09:08
>>797
さてコレをどれくらい短くできるだろうか
use strict;
open FILE, "data.csv";
my @data;
my @index;
my @ys;
for my $line (<FILE>) {
chomp $line;
unless (@index) {
@index = split(/\s*,\s*/, $line);
shift @index;
next;
}
my($y, @d) = split(/\s*,\s*/, $line);
push(@ys, $y);
for (my $i=0; $i < @d; $i++) {
$data[ $index[$i] ][ $y ] = $d[$i];
}
}
close FILE;
open FILE, ">out.csv";
for my $x (@index) {
for my $y (@ys) {
print FILE "$x, $y, $data[$x][$y]\n";
}
}