I didn't get any problem when I ran it this way:
#!/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"; }
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:
#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";
(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).

In reply to Re: Understanding variable scope in perl by liverpole
in thread Understanding variable scope in perl by BioBoy

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.