Regarding this kind of logic:
my $val1 = $next_cell_arr[0] || die "val1 is undefined!!\n";
You need to understand a subtle difference between things that evaluate to false, and things that are "undefined". In a nutshell:
use strict; my $val1; # this creates a named storage location for a scalar value, # but DOES NOT ASSIGN A VALUE -- its value is undefined. my $val2 = 0; # creates a named scalar and assigns a value, so it's d +efined # but the value will evaluate to FALSE in a # boolean sense my $val3 = ''; # similar to $val2: it's defined, it evaluates to false # in boolean tests, but in "reality", it's an # "empty string" (which $val2 is not) print "val3 is an empty string\n" if ( $val3 eq '' ); print "val2 is an empty string\n" if ( $val2 eq '' ); print "val1 is (like) an empty string\n" if ( $val1 eq ''); # this third test would generate a warning in "perl -w" my $i = 1; for ( $val1, $val2, $val3 ) { print "val$i evaluates to false\n" if ( ! $_ ); print "val$i is undefined\n" if ( ! defined( $_ )); $i++; }
Now, bear in mind that the "||" operator applies a boolean test: the expression that follows it is evaluated only if the expression that precedes it evaluates to false. Do you have empty strings or zeros in your matrix cells?

Based on the original statement of the problem, are you sure that the very first thing ever pushed onto your "@next_cell_arr" array is a defined value? Are you sure that the array is empty before you do the first of your three pushes from "@protein_matrix"?


In reply to Re^2: Understanding variable scope in perl by graff
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.