From: "Jesús Gabriel y Galán" Date: 2008-06-25T16:33:29+09:00 Subject: Re: Creating a variable based on array On Wed, Jun 25, 2008 at 7:38 AM, Tj Superfly wrote: > Hello Everyone, I'm working on a program which is posted below. > Basically my program automates file creating based off arrays at the > beginning of the program. However, I'm unsure of how to do a couple of > things. > > The line 'petpet_array = []' obviously doesn't work because it just > thinks "petpet_array", but I need it to use the item coming from the > array, so how might I be able to accomplish that? > > Basically this problem repeats itself throughout the entire program > because I'm unsure how to get it to pull from the array! Below, I have > placed stars (*) around all the 'petpet' variables that I would like it > to pull from the array and it won't work, obviously - I just don't know > how to make it work. > > If anyone can help me out with this, instruct me how to get it to do > what I'm wanting, please let me know. If you have questions, please > post. :) If I understood correctly you want to generate a set of files, that are YAML exports of arrays, each of them containing a list of URLs that are composed of a prefix, a pet name and a pet color. For each pet, you need all color combinations. Is that right? If that's correct, then you don't need to have a different array, named as the pet you are actually processing. The only places where you need the name of the pet are when creating the URL, and when calculating the name of the file. The name of the variable that's referencing the array is not relevant. I don't understand what error are you getting (when removing the * from your code), it works for me. This also works for me, with some cosmetic changes (string interpolation), and requiring yaml. require 'yaml' $defout.sync=true petpets = ["Slorg", "Sludgy", "Spyder", "Wadjet", "Buzzer", "Angelpuss", "Mallard", "Scarabug", "Cobrall", "Magaral", "Tenna", "Floud", "Slymook", "Stego", "Selket", "Warf", "Altachuck", "Khnum", "Blobagus", "Tomamu", "Psimouse", "Puppyblew", "Hopso", "Harris"] colors = ["black", "blue", "brown", "chocolate", "christmas", "clay", "cloud", "custard", "darigan", "disco", "dung", "faerie", "fire", "ghost", "glow", "gold", "green", "grey", "halloween", "ice", "invisible", "island", "jelly", "maraquan", "mutant", "orange", "pink", "pirate", "plushie", "purple", "rainbow", "red", "robot", "sketch", "snow", "spotted", "starry", "tyrannian", "white", "yellow"] petpets.each do |petpet| puts "Now creating file for " + petpet.to_s + "." # *petpet*_array = [] petpet_array = [] colors.each do |color| # url = "http://www.mysite.com/code/" + petpet.to_s + "_" + color.to_s + ".gif" url = "http://www.mysite.com/code/#{petpet}_#{color}.gif" puts url # *petpet*_array.push url petpet_array.push url end # File.open("/Users/superfly/Desktop/news_finder/arrays/" + *petpet*.to_s + "_array.yaml","w") do |out| File.open("/Users/superfly/Desktop/news_finder/arrays/#{petpet}_array.yaml","w") do |out| # out << *petpet*_array.to_yaml out << petpet_array.to_yaml end puts "The file for #{petpet} has been created successfually." puts "" puts "" end If I'm completely misundersting, please let me know, with some examples of what you need as the output and what are the errors you are experiencing. Hope this helps, Jesus.