Undefined method `empty?' for nil:NilClass (NoMethodError)


#1

Hi;
I have a script that goes through a file to match information and puts
them in different arrays. When I run the program I receive in the
following error: undefined method `empty?’ for nil:NilClass
(NoMethodError).

My code is:
Cemployee=Array.new
CemployeeID=Array.new
CemployeeName=Array.new
CemployeeGroup=Array.new
CMachineGroup=Array.new
CMachineShares=Array.new
CShareAccess=Array.new

counter=0
excelcounter1=2
excelcounter2=2
excelcounter3=2
excelcounter4=2
File.open(“D:\Reports.txt”).each { |lineinfo|
user=lineinfo
group=lineinfo
machine=lineinfo
shares=lineinfo
access=lineinfo

m = /^([C]\d+)\s(\w+.+)/.match(user)
n= /^\b(Groups:)\s.+/.match(group)
o= /^\b(Machine Group:)\s(\w+.)*/.match(machine)

p=/^\b(Share Name)\s./.match(shares)
q=/^\b(Access Level)\s.
/.match(access)

if m
CemployeeID[counter],CemployeeName[counter]=user.split(" ")
counter+=1
excelcounter1+=1

elsif p
junk,CMachineShares[counter]=group.split(": “)
CMachineShares[counter].empty?
CMachineShares[counter].slice!(”\n")
puts CMachineShares[counter]
puts CMachineShares[counter]
#$excel.Worksheets(2).Range(“A#{excelcounter4}”)
[‘Value’]=CMachineShares[counter]
#excel.Worksheets(2).Columns.AutoFit
#counter+=1
end

}


#2

The output fails when it comes to nil.
Here is a sample output:

\Server1v1\BACKUP
nil
nil
\Server4v1\BACKUP
\Server4v1\BACKUP2


#3

I figured the answer:

junk,CMachineShares[counter]=group.split(": “)
CMachineShares[counter]=CMachineShares[counter].to_a
#CMachineShares[counter].slice!(”\n")
CMachineShares[counter].delete_if {|x| x.empty?}
puts CMachineShares[counter]