in reply to foreach in HoHoA problems

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.

Replies are listed 'Best First'.
Re^2: foreach in HoHoA problems
by mdunnbass (Monk) on Oct 28, 2006 at 17:02 UTC
    Thanks, I see references to Data Dumper all over the place, but haven't figured out what it actually is or how to use it yet.

    As for perl -d, I do use that very frequently. Unfortunately in this case, the program I am writing searches a 450 Mb text file line by line searching for specific REs, saving them into %matches. So, going line by line by line by line through that process, before even getting to here would kill me. I there a way to skip the -d for a specific subroutine, yet continue it later in the program? That would help.

    Matt

      D'oh!

      man perldebug helped. I've been using the 's' key to step through my code line by line. I didn't realize I should use the 'r' key on the subroutine that did the 450 Mb file search.

      Phew!. Much better. Debugging is going to go a whole lot faster now....

      Matt

        Just using "b" (set breakpoint) and "B" (delete breakpoint) will also save you tons of debugging time: you provide a line number or a subname (e.g. "b 384" or "b bigsub"), and you can even add a condition (e.g. "b 384 (!defined $hit)". I often set a bunch of breakpoints before starting a script that has a set of "interesting" branches.

        Then do "c" (continue), and it will stop if/when it gets to any breakpoint. If the script has "use Data::Dumper", you can do "p dumper( $ref_variable )" to see how (some portion of) your data structure looks at that point.

        And that is just the tip of the iceberg.