http://qs1969.pair.com?node_id=467012


in reply to If statement problem with hash values

I have a feeling that the values in %refList are not what you expect. I notice that your example data has an underscore but none of the example $ref_filehandle values do. Could it be that you need to strip out the underscore?

A better check in the if statement may be to see if the hash value exists and then whether it is equal to the array value to avoid autovivifying non matched values.

I rewrote your snippet to run stand alone locally with some bogus data based on your examples. Does this do what you expect?

use warnings; use strict; my @resultLine = ( 'gi|14670349|ref|NM_032999.1| Homo sapiens general transcription facto +r II, i', 'one', 'gi|14670348|ref|NM_032998.1| Homo sapiens general transcription facto +r II, ii', 'two', 'gi|14670347|ref|NM_032997.1| Homo sapiens general transcription facto +r II, iii', 'three', 'gi|14670346|ref|NM_032996.1| Homo sapiens general transcription facto +r II, iv', 'four', 'gi|14670345|ref|NM_032995.1| Homo sapiens general transcription facto +r II, v', 'five', 'gi|14670344|ref|NM_032994.1| Homo sapiens general transcription facto +r II, vi', 'six', 'gi|14670343|ref|NM_032993.1| Homo sapiens general transcription facto +r II, vii', 'seven' ); my %refList; my @subjects; my $alignment = {}; while (<DATA>) { chomp; $refList{ $_ } = $_; } my $current_subject; for (@resultLine) { if (/^gi\|/) { $current_subject = $_; chomp $current_subject; push (@subjects, $current_subject); } $alignment->{$current_subject} .= $_; } for my $z (@subjects) { my @elements = split('\|', $z); if ( ! defined $elements[ 3 ] ) { print ("Parsing Error<BR>"); print ("Line $z"); } if (exists $refList{$elements[3]} and $refList{$elements[3]} eq $e +lements[3]) { print ("Already Present in file. - $elements[3]\n"); } else { print "No match in reference file. - "; print ($alignment->{$z}."\n"); print ($elements[3]."\n"); } } __DATA__ AB014570.2 AB055861.1 AB067522.1 AB073617.1 AC004166.12 AC004851.2 AC004867.5 AC004883.3 AC005077.5 AC005080.2 NM_032997.1 NM_032993.1 NM_032999.1