However, some things look odd to me:
You have already declared my %headerHash; outside of the loop. Here $headerHash is declared as a scalar, not a hash! Perl does allow different name spaces for hash vs scalar. You can have both a scalar and a hash named "headerHash", but in this case, I think this is a bad idea. I suggest you change this scalar version of $headerHash to something else. Your code is very confusing.my $headerHash; $headerHash{$1} = $2;
Update: Even if you move my $headerhash; above the while loop, On line 28, print OUTFILE $headerHash, "\n", $seq, "\n";, that will create a runtime error because there is nowhere that I can see where this scalar $headerhash is assigned any value, it will be "undef".
Maybe you are confused about hash syntax? A hash like %headerhash is accessed with 2 things, a key and a value, like $hash{$key}=$value.
Be careful, something like %hash=55; doesn't do what you think!! This increases the size of the hash, i.e. more buckets. This doesn't assign a value to the hash. Consider:
Perl starts a new hash with a default of 8 buckets. When it needs to grow the hash, it doubles the number of buckets. 8,16,32,64,etc. I have bench marked presetting big hashes to big bucket sizes to prevent this auto re-sizing, but found out that this makes almost no difference in performance. Perl is surprisingly efficient at this transparent operation. It is best to just let Perl "do its thing" without trying to overly "help it". I just mention this here to show some perhaps error that could produce some very unexpected results if you botch the hash assignment syntax.#!/usr/bin/perl use strict; my %hash; #defaults to 8 buckets $hash{a}=33; #use one of the buckets my $buckets = %hash; print "$buckets\n"; #prints 1/8, 1 of 8 buckets used keys(%hash)=32; #increase size of hash to 32 buckets $buckets = %hash; print "$buckets\n"; #prints 1/32 1 of 32 buckets used
In reply to Re: While loop with nested if statements
by Marshall
in thread While loop with nested if statements
by lairel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |