If you haven't been using Data::Dumper yet, now is the time to start...
use Data::Dumper; # add this near the top of your script: # ... now, down at line 383 (had been 382 before adding "use Data::Dum +per": SITEKEY: for $sitekey (sort {$a <=> $b } keys %{$matches{$fasta +seq}}) { print "\$matches{$fastaseq}{$sitekey} is:\n", Dumper( $matches{$fastaseq}{$sitekey} ); # add this SET: foreach $hit ( ... ) { # the above print statement used to be here
Also, if you haven't started using "perl -d" to run your script, it's time to learn about the perl debugger, so you can step through your code and check what is being assigned to your structure as it happens.

One other hint: if you're looking at data structure trouble at line 384 and you've lost your train of thought, your problem may be "fasta pasta" -- i.e. spaghetti code. (Sorry, couldn't resist.)

Try modularizing -- identify functions or code blocks that can be made fairly independent, put them into separate files that simply define subroutines, and put "require" statements into the main script to load those other files.

This will make it easier to test things, and so long as the different "modules" really function independently, you'll find it easier to focus your attention on the problem areas, because they will be smaller. The discipline of not using or altering global variables within subroutines (because the subs will be defined in separate source files), will do you good.


In reply to Re: foreach in HoHoA problems by graff
in thread foreach in HoHoA problems by mdunnbass

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.