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.
In reply to Re^2: how to sum over rows based on column headings in perl
by angerusso
in thread how to sum over rows based on column headings in perl
by angerusso
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |