contacts_r = File.open("user_contacts.txt", "r")
user_contacts = []
contacts_r.readlines.each { |line|
user_contacts << line.chomp
}
$c = Hash[user_contacts.map { |x| ["$#{x}_called", Array.new] } ]
When I try to add info in the desired array...
$c["#{name}_called"] << 1
I get a undefined method '<<' for nil:NilClass (NoMethodError)
when I use..
puts $c
the output looks like
{"$robert_called"=>[]}
I'm trying to make it look like
{"$robert_called"=>[1]}
name? If it's not"robert", the error is obvious. Your code otherwise looks okay. (I'd probably contract the whole thing intouser_contacts = File.read(filename).lines.map(&:chomp)or the lazieruser_contacts = File.open(filename) { |f| f.each_line.map(&:chomp) }, and use a hash with a default proc (c = Hash.new { |h, k| h[k] = [] }) so I don't have to initialise it at all... Also, beware global variables, they have a nasty habit of biting you in the behind."#{name}"i just meant thats where the namesgo...its no actualy part of the code :\ @Amadan