If you had some example input, I could perhaps run the code. Right now all I can see are the compiler errors.

However, some things look odd to me:

my $headerHash; $headerHash{$1} = $2;
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.

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:

#!/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
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.

In reply to Re: While loop with nested if statements by Marshall
in thread While loop with nested if statements by lairel

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.