array difference

J

Jeffrey Bowen

I’m trying to create an array containing the
difference of the two other arrays. When I create the
arrays manual I have no problems.

a = ["0001", "0002"]
b = ["0001", "0002", "0003"]
c = b - a
puts c
c -> 0003

However when the array is created from data in a file
d will equal the first array not the difference
between the two.

File.open("datafilelist.txt").each { |h| data_files1
<< h}

d = data_files1 - data_files
puts d
-> 0001, 0002

Thoughts?

Jeff Bowen



____________________________________________________________________________________
Luggage? GPS? Comic books?
Check out fitting gifts for grads at Yahoo! Search
http://search.yahoo.com/search?fr=oni_on_mail&p=graduation+gifts&cs=bz
 
X

Xavier Noria

I=92m trying to create an array containing the
difference of the two other arrays. When I create the
arrays manual I have no problems.

a =3D ["0001", "0002"]
b =3D ["0001", "0002", "0003"]
c =3D b - a
puts c
c -> 0003

However when the array is created from data in a file
d will equal the first array not the difference
between the two.

File.open("datafilelist.txt").each { |h| data_files1
<< h}

d =3D data_files1 - data_files
puts d
-> 0001, 0002

I guess the trailing newline in the elements of data_files1 is the =20
culprit. In that case push h.chomp instead of h. In any case, inspect =20=

the arrays.

-- fxn
 
R

Rob Biedenharn

I=92m trying to create an array containing the
difference of the two other arrays. When I create the
arrays manual I have no problems.

a =3D ["0001", "0002"]
b =3D ["0001", "0002", "0003"]
c =3D b - a
puts c
c -> 0003

However when the array is created from data in a file
d will equal the first array not the difference
between the two.

File.open("datafilelist.txt").each { |h| data_files1
<< h}

d =3D data_files1 - data_files
puts d
-> 0001, 0002

Thoughts?

Jeff Bowen

You haven't shown enough code to get any help! What is data_files? =20
Giving us a sample of the contents of "datafilelist.txt" would be =20
quite useful, too.

-Rob

Rob Biedenharn http://agileconsultingllc.com
(e-mail address removed)
k
 

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
474,264
Messages
2,571,315
Members
47,996
Latest member
LaurenFola

Latest Threads

Top