Hi everyone, I have the following piece of code:
my @set_S; my @nset_S; my @epsilons; my $r=0; for $r (0..99){ $set_S[$r] = [$r]; } $q = 2; $sigma_square = 0.1 * $q; for my $err (0..$#set_S){ $epsilons[$err] = rand($sigma_square + 1); } my $t=0; for my $s (0..$#set_S){ print "@{$set_S[$s]}\t$epsilons[$s]\t"; @{$set_S[$s]} = @{$set_S[$s]} + $epsilons[$s]; print @{$set_S[$s]}, "\n"; $t++; }
The output looks like:
0 0.16702880859375 1.16702880859375 1 0.54862060546875 1.54862060546875 2 0.75128173828125 1.75128173828125 3 0.67547607421875 1.67547607421875 4 0.58304443359375 1.58304443359375 5 0.98953857421875 1.98953857421875 6 0.07342529296875 1.07342529296875 7 0.43919677734375 1.43919677734375 8 0.70689697265625 1.70689697265625
Apparently, my question is :Why is the addition wrong?? Why is perl turning the first columns to 1's when adding them to the second column?? How do i solve this? I appreciate your prompt response. Thanks

In reply to Turning numbers to 1! by perlrocks

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.