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

In reply to Re: If statement problem with hash values by thundergnat
in thread If statement problem with hash values by MonkPaul

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.