To_Bz has asked for the wisdom of the Perl Monks concerning the following question:
I have two input files: table.txt and values.txt
table.txt looks like the following:
xanmn_chr09_0114-xanmn_chr09_0114 3346 xanmn_chr09_0129-xanmn_chr09_0129 3358 xanmn_chr09_0116-xanmn_chr09_0116 3348 xanmn_chr09_0127-xanmn_chr09_0127 3354
3346 1933 1371 1448 2762 1395
open(FILE1, "<", table.txt) open(FILE2, "<", values.txt) my %ids2proteins=(); while(my $row = <FILE2>){ chomp $row; my @column = split(/\t/, $row); my $protein_number = $column[0]; while(my $line= <FILE1>){ chomp $line; my @fields = split(/\t/, $line); my ($ids,$proteins) = ($fields[0],$fields[1]); $ids2proteins{$ids} = $proteins; foreach my $keys(keys %ids2proteins){ my $values = $ids2proteins{$keys}; if($values eq $protein_number){ print "$keys => $protein_number"; }}}}
Everything works well until the if inside the foreach. I'm relatively new in Perl, and I think that I have a problem with the logic of the problem.
So, I will really appreciate the help.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to compare hash values to array values in Perl
by LanX (Saint) on May 14, 2014 at 04:30 UTC | |
|
Re: How to compare hash values to array values in Perl
by NetWallah (Canon) on May 14, 2014 at 05:28 UTC | |
by kcott (Archbishop) on May 14, 2014 at 06:52 UTC | |
|
Re: How to compare hash values to array values in Perl
by kcott (Archbishop) on May 14, 2014 at 05:18 UTC | |
|
Re: How to compare hash values to array values in Perl
by vinoth.ree (Monsignor) on May 14, 2014 at 05:56 UTC | |
|
Re: How to compare hash values to array values in Perl
by LanX (Saint) on May 14, 2014 at 15:14 UTC | |
by morgon (Priest) on May 14, 2014 at 15:22 UTC | |
|
Re: How to compare hash values to array values in Perl
by Lennotoecom (Pilgrim) on May 14, 2014 at 18:57 UTC |