in reply to Re: how to sum over rows based on column headings in perl
in thread how to sum over rows based on column headings in perl
I am trying to understand your code by modifying it myself and trying to read the data through a file
#!/usr/bin/perl -w use strict; use warnings; use autodie; if (@ARGV != 1){ print "USAGE: ./parse-counts.pl file\n"; exit(-1); } my $mutfile = $ARGV[0]; my (%counts, %unique, %masks); my ($headname, @unique) = grep !$unique{$_}++, my @headers = split ' ' +, <DATA>; for my $label ( @unique ) { $masks{$label} = join ' ', map { $_ eq $label ? 'M' : '_' } @headers[1..$#headers]; } my $line; open(INPUTR,"<$mutfile") || die "Can't open \$mutfile for reading. \n" +; while($line=<INPUTR>){ #while(<DATA>) { chomp $line; s/\s+/ /g; # for uniform spacing my ($name, $letters) = split ' ', $line, 2; $counts{$name}{$line} += ($masks{$line} | $letters) =~ /M/ for @un +ique; } print "$headname @unique\n"; print "$line @{ $counts{$_} }{@unique}\n" for sort keys %counts;
I am sorry i don't understand what I did wrong as now I get error as:
./parse-counts.pl junk.txt Missing right curly or square bracket at ./parse-counts.pl line 36, at + end of line syntax error at ./parse-counts.pl line 36, at EOF Execution of ./parse-counts.pl aborted due to compilation errors.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: how to sum over rows based on column headings in perl
by 1nickt (Canon) on Jul 31, 2015 at 17:03 UTC | |
by angerusso (Novice) on Jul 31, 2015 at 19:07 UTC | |
by Anonymous Monk on Jul 31, 2015 at 19:29 UTC | |
by angerusso (Novice) on Jul 31, 2015 at 19:58 UTC | |
by Anonymous Monk on Jul 31, 2015 at 20:09 UTC | |
|
Re^3: how to sum over rows based on column headings in perl
by Anonymous Monk on Jul 31, 2015 at 17:12 UTC | |
by angerusso (Novice) on Jul 31, 2015 at 18:48 UTC |