Hi,
I used that code, which works fine for me:
$\ = $/; sub add{ my ($i, $j, $add) = @_; $_{value}[$i][$j] += $add; } while(<DATA>){ $tc ++; print "[$tc]"; ($n, $m) = split; for $i (1 .. $n){ $_ = <DATA>, chomp; for $j (1 .. $m){ $_{value}[$i][$j] = substr $_, $j - 1, 1; } } &add(2, 3, 5); for $i (1 .. $n){ print join " ", @{ $_{value}[$i] }; } } __DATA__ 3 3 011 111 111 6 7 1101011 0111111 1111101 1111111 1111110 0111111
OUTPUT:
[1] 0 1 1 1 1 6 1 1 1 [2] 1 1 0 1 0 1 1 0 1 6 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1

... but later I wanted to collect all my matrixes, so I tried to replace this "$_{value}[$i]" with that "$_[$tc]{value}[$i]" (I inserted [$tc] in all such places). And now seems that my subroutine fails? The OUTPUT is:
[1] 0 1 1 1 1 1 1 1 1 [2] 1 1 0 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1
Program:
$\ = $/; sub add{ my ($i, $j, $add) = @_; $_[$tc]{value}[$i][$j] += $add; } while(<DATA>){ $tc ++; print "[$tc]"; ($n, $m) = split; for $i (1 .. $n){ $_ = <DATA>, chomp; for $j (1 .. $m){ $_[$tc]{value}[$i][$j] = substr $_, $j - 1, 1; } } &add(2, 3, 5); for $i (1 .. $n){ print join " ", @{ $_[$tc]{value}[$i] }; } } __DATA__ 3 3 011 111 111 6 7 1101011 0111111 1111101 1111111 1111110 0111111
I can't understand why it fails.

In reply to can't find mistake. lost in references by rsFalse

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.