gghelpneeded has asked for the wisdom of the Perl Monks concerning the following question:
below is a question i need help addressing. the script works in the way i want it to. i just need help finishing it. my script takes one file and creates a hash from it and then takes the second file and creates a key from it. the last part is suppose to take the keys that are the same and print out the corresponding value along with the key from the first file. I can get the key but not the value
heres and example of the data.
file 1
name1 ABCD
name2 BCD
name3 ASCDA
name4 AAAAA
file 2
name1 0.2
name5 0.3
name4 0.0002
name7 0.222
my %s; open(FILE1, $ARGV[0]) or die "Cannot open the file: $!"; my $hash_key; my $hash_value; while (my $line = <FILE1>) { if ($line =~ /^>(\S+)/) { $hash_key = $1; } elsif ($line =~ /\S/) { chomp $line; $hash_value = $line; $s{$hash_key} = $hash_value; } } foreach my $hash_key1 (keys %s) { print "$hash_key1\t$s{$hash_key1}\n"; } my %n; open(FILE2, $ARGV[1]) or die "Cannot open the file: $!"; my $hash_key2; my $hash_value2; while (my $line2 = <FILE2>) { if ($line2 =~ /(\S*)/) { $hash_key2 = $1; $hash_value2 = $line2; $n{$hash_key2} = $hash_value2; } elsif ($line2 =~ /\S/) { chomp $line2; } } foreach my $hash_key3 (keys %n) { print "$hash_key3\n"; } my @n = (); foreach (keys %n) { push(@n, $_) if exists $s{$_}; #this is where i am having trouble. tried using dumper and #grep didnt + help print "$_\n"; } close FILE1; close FILE2; exit;
help would be appreciated. cheers.
|
|---|