Hello again, Paul

I found another problem.  I am sorry not to include this in the previous po=
st.

As you set "opf" inside the each_line loop, "opt.puts line"(where I add a m=
ark)
won't work when both contents of ifs are not processed, i.e. the opf
is not defined
inside the loop.

To solve this problem, add definition of opf ("opf =3D nil") before the loo=
p.


Look at next examples

-- code 1
flag =3D false

1.upto(3) do |i|
  unless flag
    bad_var =3D 1000
    flag =3D true
  end
  puts "#{i}, #{bad_var.nil?}"
end

-- result 1
1, false
2, true
3, true

-- code 2
flag =3D false

bad_var =3D nil # << bad_var is defined here
1.upto(3) do |i|
  unless flag
    bad_var =3D 1000
    flag =3D true
  end
  puts "#{i}, #{bad_var.nil?}"
end

-- result 2
1, false
2, false
3, false


On Fri, Apr 1, 2011 at 4:31 PM, Paul Joyce <pjoyce / whatsthis.ie> wrote:
>
> #puts template
> ipf =3D File.new("All-Contracts-29-Mar-11.csv","r")
> =A0 =A0 =A0ipf.each_line { |line|
> =A0 =A0 =A0next if line.match(/^$/)
> =A0 =A0 =A0data =3D line.split(",")
> =A0 =A0 =A0if curr =3D=3D "x" =A0 =A0 # =A0Initialize
> =A0 =A0 =A0 =A0puts "Initialize . . " + data[0]
> =A0 =A0 =A0 =A0opf =3D File.new(data[0] + '-feeder-customer.csv',"r+")
> =A0 =A0 =A0 =A0opf.puts colhead =A0 # <----- =A0HERE
> =A0 =A0 =A0end
> =A0 =A0 =A0if curr !=3D data[0] and curr !=3D "x"
> =A0 =A0 =A0 =A0 puts "New File . . . " + data[0]
> =A0 =A0 =A0 =A0 opf.close
> =A0 =A0 =A0 =A0 opf =3D File.new(data[0] + "-feeder-customer.csv","r+")
> =A0 =A0 =A0 =A0 opf.puts colhead
> =A0 =A0 =A0end
> =A0 =A0 =A0opf.puts line ## <-- This occurs a nil class error
> =A0 =A0 =A0curr =3D data[0]
> =A0 =A0}
> ipf.close;
> opf.close;
>
> puts 'DONE.'
>

--=20
Haruka YAGNI