Essentially I want to do the following:
list = “url1, irl2, url3, url4, url5”
while [ list ]; #in other words, we loop 5 times or = # things in list
do #A Bunch of Stuff 1 #A Bunch of Stuff 2
done
My list is essentially a list of URLs. I’m most familiar with doing it
in a text list, but I guess I could create an array, count that array,
and then do a loop with a counter.
Essentially I want to do the following:
list = “url1, irl2, url3, url4, url5”
while [ list ]; #in other words, we loop 5 times or = # things in list
do #A Bunch of Stuff 1 #A Bunch of Stuff 2
done
list = “A,B,C,D”
list.split(", ").each do |url|
puts “URL IS:”+url
end
Output: URL IS:A,B,C,D
Is using an array a “more correct” way to do it in Ruby?
Your first example began with
list = “url1, irl2, url3, url4, url5”
but now your list looks like this:
list = “A,B,C,D”
The spaces are missing, so splitting on a comma followed by a space does
not split anything in your second example. In your first example, it
produces an array with 4 elements. In your second list it produces an
array with one elemement: “A,B,C,D”
Thank you guys.
Obviously I need to be more aware of my white space in Ruby. I’ve put
the two examples below - both one via a list and one via an array.
List
list = “url1, url2, url3, url4, url5”
list.split(", ").each do |url|
puts url
end
Don’t let white space get you down…
list.split(/\s*,\s*/).each do
ilan
Darin Ginther wrote:
Thank you guys.
Obviously I need to be more aware of my white space in Ruby. I’ve put
the two examples below - both one via a list and one via an array.
List
list = “url1, url2, url3, url4, url5”
list.split(", ").each do |url|
puts url
end