in reply to Understanding variable scope in perl
But if you're getting an error on such-and-such a line, I'd like to suggest you try putting debugging right near that line, and breaking it up into multiple statements, so you can see the intermediate values of interest:#!/usr/bin/perl -w + # Strict (always using these 2 lines will save you much grief!) use strict; use warnings; + # Global variables my @next_cell_arr; my @protein_matrix; my @sequence_1_arr; my @sequence_2_arr; my $row = 0; my $col = 0; my $dowhat = 0; + # Generate some test data $protein_matrix[$row][$col] = 1; $protein_matrix[$row][$col+1] = 2; $protein_matrix[$row+1][$col] = 3; $protein_matrix[$row+1][$col+1] = 4; + # BioBoy's code follows push( @next_cell_arr, $protein_matrix[$row][$col+1] ); push( @next_cell_arr, $protein_matrix[$row+1][$col+1] ); push( @next_cell_arr, $protein_matrix[$row+1][$col] ); + # - debug #$arr_len = scalar @next_cell_arr; #for( $var = 0; $var < $arr_len; $var++ ){ # print $next_cell_arr[$var]; # print "\n"; #} #print "\n\n"; #exit; # - debug + # - if all values are equal, then the sequence gets a match of suffers + a mismatch # (diagonal move), and not a gap penalty. This also saves me from hav +ing to # compute the max of the three cells if( ($next_cell_arr[0] == $next_cell_arr[1]) && ($next_cell_arr[1] == +$next_cell_arr[2]) ){ push( @sequence_2_arr, $protein_matrix[0][$col+1] ); push( @sequence_1_arr, $protein_matrix[$row+1][0] ); $dowhat = "diagonal"; }
(Note that I use the notation "TFD" to mean that a line or a sequence of lines is "temporary for debugging", and can be removed once I uncovered the cause of the problem).#TFD (Temporary for debug)>> my $cell0 = $next_cell_arr[0] || die "cell0 undef!\n"; printf "Cell0 = + %s\n", $cell0; my $cell1 = $next_cell_arr[1] || die "cell1 undef!\n"; printf "Cell1 = + %s\n", $cell1; my $cell2 = $next_cell_arr[2] || die "cell2 undef!\n"; printf "Cell2 = + %s\n", $cell2; if( ($cell0 == $cell1) && ($cell1 == $cell2) ){ print "TFD> All 3 cell values defined and EQUAL\n"; push( @sequence_2_arr, $protein_matrix[0][$col+1] ); push( @sequence_1_arr, $protein_matrix[$row+1][0] ); $dowhat = "diagonal"; } print "TFD> All 3 cell values defined, but NOT equal\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Understanding variable scope in perl
by BioBoy (Novice) on Sep 29, 2005 at 18:11 UTC | |
by kwaping (Priest) on Sep 29, 2005 at 19:09 UTC | |
by liverpole (Monsignor) on Sep 29, 2005 at 19:02 UTC |