Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- open my $in, '<', 'test.txt' or die;
- my $freq = [];
- my $word = [];
- while (<$in>) {
- chomp;
- my @line = split ',';
- push @$word, @line;
- for (my $i = 0; $i <= $#line; ++$i) {
- $freq->[$i] or $freq->[$i] = {};
- ++$freq->[$i]->{$line[$i]};
- }
- }
- close $in;
- my %h = map { $_ => 1 } @$word;
- my @uniq_word = sort keys %h;
- my $all = {};
- for (my $i = 0; $i < @$freq; ++$i) {
- print "column $i\n";
- for (@uniq_word) {
- $freq->[$i]->{$_} or $freq->[$i]->{$_} = 0;
- $all->{$_} or $all->{$_} = 0;
- $all->{$_} += $freq->[$i]->{$_};
- print "$_ = $freq->[$i]->{$_}\n";
- }
- }
- print "all\n";
- print "$_ = $all->{$_}\n" for (@uniq_word);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement