You're a victim of typos. When I ran your code through perl -c, I got a log of messages like:
Global symbol "$conig" requires explicit package name at 349376.pl line 555.
You spell that variable as "$contig" in some places and "$conig" in others. However, that's not the entire scope of your problem. You declare $contig as my in different scopes, so I'd expect that your code wouldn't run as you expect. A short demonstration of what I'm talking about:
my $contig = 3; my $foo = 6; if ($foo < 8) { my $contig = 5; } print "contig = $contig\n"; __END__ contig = 3

As a matter of style, you should probably avoid the whole "if..elsif..elsif..elsif..." routine for this. As I'm sure you found out, it's very tedious to type. A more visually appealing (and easier to maintain) to do something like the following:

my %master = ( 167280 => (chromosome => 1, contig => 'NT_077402.1'), 217280 => (chromosome => 1, contig => 'gap'), 257582 => (chromosome => 1, contig => 'NT_077911.1'), # etc ); NUMBER: foreach my $number (@numbers) { foreach my $key (sort { $a <=> $b } keys %master) { if ($number < $key) { my $chromosome = $master{$key}{chromosome}; my $contig = $master{$key}{contig}; #do whatever processing here; I'll just print print "chromosome = $chromosome, contig = $contig\n"; next NUMBER; } } }
This style has the advantage of maintainability. Should you find an error in your processing logic (for example, if I found that I had misspelled 'chromosome' in my print statement'), you have exactly one place to fix it.

Hope this helps,
thor

Update: I just thought of another reason to avoid the "if..elsif..." paradigm. Once, someone came to me for help in trying to run a tool that had such a thing in it. perl core dumped because the script was too large. I converted the solution to a hash, and it ran in no time at all.

In reply to Re: Selecting a random number, and back calculating to chromosome and contig! by thor
in thread Selecting a random number, and back calculating to chromosome and contig! by Sameet

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.