Skip to content

Instantly share code, notes, and snippets.

@davetang
Last active July 30, 2021 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save davetang/a7918eac9b030d09291a to your computer and use it in GitHub Desktop.
Save davetang/a7918eac9b030d09291a to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
my $data = [];
my $t_data = [];
while(<>){
chomp;
#skip comments
next if /^#/;
#skip lines without anything
next if /^$/;
#split lines on tabs
my @s = split(/\t/);
#store each line, which has been split on tabs
#in the array reference as an array reference
push(@{$data}, \@s);
}
#loop through array reference
for my $row (@{$data}){
#go through each array reference
#each array element is each row of the data
for my $col (0 .. $#{$row}){
#each row of $t_data is an array reference
#that is being populated with the $data columns
push(@{$t_data->[$col]}, $row->[$col]);
}
}
for my $row (@$t_data){
my $line_to_print = '';
for my $col (@{$row}){
$line_to_print .= "$col\t";
}
$line_to_print =~ s/\t$//;
print "$line_to_print\n";
}
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment