Hi all,
I am having problem with array while setting the flag,
actaully when i get the array size should be all 44 other wise it should
come to flag 0, now my array counts are 42 42 44, so it shows the flag =
0, but for me it showing flag =1 , i think i have some loop problem,
please let me know why?
@split_record.each do |v|
@split_data=v.split("*")
@get_size=@split_data.size // after split my array is
42 42 44
if @get_size == 44
@flag=1
else
@flag=0
end
end
return @flag
In this i am checking 3 records, i should get flag=1 if all are 44,
but at present not matching, so it should shows floag=0, but for its
showing flag =1, please let me know the problem, thanks in advance
You should seriously consider reading
http://whytheluckystiff.net/ruby/pickaxe/
And this question is suited for ruby-lang
On 10/16/07, Vidya V. [email protected] wrote:
@split_record.each do |v|
In this i am checking 3 records, i should get flag=1 if all are 44,
but at present not matching, so it should shows floag=0, but for its
showing flag =1, please let me know the problem, thanks in advance
Posted via http://www.ruby-forum.com/.
–
Cheers!
Vidya V. wrote:
Hi all,
@split_record.each do |v|
@split_data=v.split(“*”)
@get_size=@split_data.size // after split my array is
42 42 44
if @get_size == 44
@flag=1
else
@flag=0
end
end
return @flag
-
just from the code here it seems there is no need for u to use global
variables (why not use local variables? better for mem usage). →
instead of using
@get_size
why not just use
get_size
-
the reason, simply, that the @flag=1 has to do with the fact that in
the last iteration (=loop) the flag is set to one because the last var
in the array is
44, so if u check the value of the flag per loop you’ll get:
(begin loop)
loop 1: @flag=0
loop 2: @flag=0
loop 3: @flag=1
(end loop)
at the end of the loop, the variable @flag equals 1.
AND:
Posted by Pratik Naik (pratik)
on 16.10.2007 11:51
(Received via mailing list)
You should seriously consider reading
http://whytheluckystiff.net/ruby/pickaxe/
And this question is suited for ruby-lang (forum#4)
enjoy.