Each iteration of your while loop overwrites the variables $V1 and $V2, so by the time your while loop is complete, only the final line's values are there.

Something like this (untested) should work:

use Bio::SeqIO; my (%all_V1, %all_V2); # hashes to store $V1 and $V2 open (LIST1, "list"); while (<LIST1>) { ($V1, $V2) = split /\t/; $all_V1{$V1}++; # FIX: this line and the next were originally $all_V2{$V2}++; # incorrectly prefixed with "push". } close(LIST1); my $seqIO_object = Bio::SeqIO->new(-file=>"infile.gb"); my $seq_object = $seqio_object ->next_seq; for my $feat_object ($seq_object->get_SeqFeatures){ if ($feat_object->primary_tag eq "CDS"){ if ($feat_object->has_tag('locus_tag')){ for my $V3 ($feat_object ->get_tag_values('locus_tag')){ if (exists $all_V1{$V3}){ print "locus_tag: ", $V3, " is unique\n"; } } } } }

By the way, $V1, $V2 and $V3 are very badly named variables. If you want to be able to come back to your code in a few months and fix a bug, it really helps if your variables have useful names.


In reply to Re: Question on loops by tobyink
in thread Question on loops by Bforde

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.