i using below commands find size of array
$size_x = @x; or
$size_x = $#x+1 ; both work when use in simple statement. when use them in loop, size becomes 1 number bigger. why happening in way. below example:
for ($i=1;$i<=10;$i++){ if (1**2+2**2>=1){ @x[$i] =2+3; $size_x = @x; } print "my size $size_x\n"; } here results:
my size 2 size 3 size 4 size 5 size 6 size 7 size 8 size 9 size 10 size 11 the answer should 1 10 instead of 2 11, think. better way size correctly? thanks.
just side note: array elements in perl denoted starting $, not @. @x whole array, while $x[$i] $i'th element of array @x.
use warnings; should warn this.
(i know more comment answer, newbie i'm not yet allowed comment. sorry.)
Comments
Post a Comment