This should be really simple but for some reason it's not. All I'm trying to do is count the number of IP addresses in a file, and I really did not expect to have any trouble with this at all.
reg = IO.read(ARGV[0])
rr += reg.scan /(?:\d{1,3}\.){3}\d{1,3}/
puts rr.size
I've manually checked and there should be somewhere around 1000 ip addresses in the particular file I'm using. All this code does is look for IPs in the file using regex, and then puts all of the IPs into an array. Then it uses Ruby's .size method to count how many items are in the array. For some reason this is inaccurate though, telling me there's over 40,000 IPs in the file. Which is impossible. There's no way. The code used to look this this:
reg = IO.read(ARGV[0])
rr = []
r = reg.scan /(?:\d{1,3}\.){3}\d{1,3}/
rr << r
puts rr.size
But that always returned 1, no matter what. Now I know everyone in the world hates Ruby, but I feel like my particular problem has more to do with general coding concepts.