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

A

anon1m0us

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

}
 
A

anon1m0us

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

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

anon1m0us

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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top