in reply to Selecting a random number, and back calculating to chromosome and contig!
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:
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.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; } } }
Hope this helps,
thor
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Selecting a random number, and back calculating to chromosome and contig!
by Sameet (Beadle) on Apr 30, 2004 at 18:01 UTC | |
by biosysadmin (Deacon) on Apr 30, 2004 at 20:12 UTC | |
by Sameet (Beadle) on May 04, 2004 at 05:57 UTC | |
by tedrek (Pilgrim) on May 05, 2004 at 19:12 UTC | |
by Sameet (Beadle) on May 06, 2004 at 07:06 UTC |