aboutsummaryrefslogtreecommitdiff
path: root/challenge-110/wlmb/perl/ch-2a.pl
blob: 13633682313b93b841d6900f70928ce7d32cb853 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/env perl
# Perl weekly challenge 110
# Task 2: Transpose file
#
# CSV version
# See https://wlmb.github.io/2021/04/27/PWC110/#task-2-transpose-file
use strict;
use warnings;
use v5.12;
use List::Util qw(max);
use Text::CSV qw(csv);
my $input=csv(in=>*ARGV);
my $Ncols=max map {scalar @{$input->[$_]}} @$input-1;
my $transposed=[map {my $c=$_; [map {$input->[$_][$c]} 0..@$input-1]} 0..$Ncols-1];
csv(in=>$transposed, out=>*STDOUT, eol=>$/);