SoFunction
Updated on 2025-04-07

Perl's implementation code for perl to replace rows and columns with different lengths


#!/usr/bin/perl -w
my @matrix;
my $max_len = 0;
while(<DATA>){
chomp;
s/,$//g;
my @fields = split /,/, $_;
my $len = @fields;
$max_len = $max_len > $len ? $max_len : $len;
push @matrix, [@fields];
}
for my $col (0..$max_len - 1){
for my $line (@matrix){
print $line->[$col] || ' ', ',';
}
print "\n";
}
__DATA__
1,2,3,4,5,6,
7,8,9,
10,11,12,13,