Good evening Monks!
I am struggling to deal with a case when a hash key has two values. I have written a basic program to try and illustrate what I am trying to do.
fruit.txt
strands.txtapple cherry peach banana cherry
Using the fruit.txt file, I would like to be able to print 'cherry' if it is matched as positive, as well as if it is negative. Is there anyway I can do this in perl?apple + cherry - cherry + peach + banana -
Any help would be gratefully received. - E#!/usr/bin/perl -w use strict; use Data::Dumper; my $inputfile1 = $ARGV[0]; my $inputfile2 = $ARGV[1]; open (FILE1, $inputfile1) or die; open (FILE2, $inputfile2) or die; my @fruit = <FILE1>; # fruit.txt close FILE1; my @strands = <FILE2>; ## strands.txt close FILE2; my (@fruitcolumn, @strand_direction, %strands, $key, $value); foreach my $line(@strands) { my @colsplit = split("\t", $line); push (@fruitcolumn, $colsplit[0]); push (@strand_direction, $colsplit[1]); } s/\s+$// foreach @strand_direction; s/\s+$// foreach @fruit; while ($key = shift (@fruitcolumn)) { $value = shift (@strand_direction); push @{$strands{$key}}, $value; } foreach my $line (@fruit) { if ($strands{$line} =~ m/\+/) { print "my positives are $line", "\n"; } elsif($strands{$line} =~ m/\-/) { print "my negatives are $line", "\n"; } }
In reply to Unique key identifer? by lecb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |