About Matrix

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#!/usr/bin/env perl6

use v6;

sub MAIN(Str :f($file)) {
	my @lines 	= $file.IO.lines;
	my @subjects 	= @lines.shift.words;
	my @datas	= [,] @lines.map: *.words[1 .. * - 1];
	my @names	= [,] @lines.map: *.words[0];

	my @row = @datas.map: -> @r { @r <</>> [+] @r };
	my @col = [Z] ([Z] @datas).map: -> @c { @c <</>> [+] @c }; 
	my @all = @datas.map: -> @r { @r <</>> ([+] @datas.map(|*)) };
	
	print(@subjects, @names, @row);
	print(@subjects, @names, @col);
	print(@subjects, @names, @all);
}

sub print(@subjects, @names, @data) {
	say @subjects.join("\t");
	for (@names Z @data) -> @one {
		say @one.map(|*).join("\t");
	}
}