Hi, I'm wondering how reliable perl comparisons and hashes are, and if there's something I can do instead or fix. I'm using perl 5.16.1, 5.16.2, or 5.18.2.

I want to find gene names in a bed file with multiple assigned ensembl ids, and regular gene names with multiple ensembl ids. For easier reading, x with multiple z, and y with multiple z. I want to push those values into the respective arrays. These are the variables:

my %bedgenenames; my @bedrepeats; my %realgenenames; my @haplotyperegionrepeats;

When I try this, I get the correct outputs for the first statement and incorrect outputs for the second.

chomp($entry); my @array = grep {$_} split /[\t ]/, $entry; unless(exists($bedgenenames{"$array[3]"})){ $bedgenenames{"$array[3]"}="$array[6]"; }elsif("$bedgenenames{$array[3]}" ne "array[6]"){ push @bedrepeats, "$array[3]"; print "$array[3] for $bedgenenames{$array[3]} and $array[6] bed\n" +; } unless(exists($realgenenames{"$array[8]"})){ $realgenenames{"$array[8]"}="$array[6]"; }elsif("$realgenenames{$array[8]}" ne "array[6]"){ push @haplotyperegionrepeats, "$array[8]"; print "$array[8] for $realgenenames{$array[8]} and $array[6] haplo +type\n"; }

This is the output for the first(correct, where the two ensembl ids are different) and second(incorrect, where the two ensembl ids are the same):

WASH5P14829 for ENSG00000223972 and ENSG00000227232 bed WASH7P for ENSG00000227232 and ENSG00000227232 haplotype
How can I solve this?

In reply to How can I solve this hash issue? by adur

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.