将多个参数发送到hash



hy我解析文件以查找一些参数,如uid、dbname和url。我尝试做的是在csv文件中发送散列中的所有值

当我解析我的hash(res_licence)时,我只有3个像一样的参数

uid,uid']='adfs';url,url']='https://mydom.sandboxbk.net';数据库名称,

我找不到他为什么越权:(

res_licence = Hash.new
array = Dir.glob('configuration_*')
array.each do |f|
       file = File.open(f ,"r")
      lines = file.readlines
  lines.each do |line|
  if line.include? 'uid'
     uid = line.match(/(?=uid)(.*)/)
     puts ""
     puts "==>#{uid} "
     #res_licence = { uid: uid}
  end 

 if line.include? 'url'
     url = line.match(/(?=url)(.*)/)
     puts "==>#{url} "
       #res_licence = {  url: url}
  end 

 if line.include? 'dbname'
     dbname = line.match(/(?=dbname)(.*)/)
     puts "=>#{dbname} "
  end 
    res_licence = {uid: uid, url: url, dbname: dbname}
   end
 end

我找到了问题的解决方案,这次我没有uid=>"xxx",url=>"xxx"

configs = {}
Dir.glob('configuration_*').each do |filename|
 configs[filename]= Hash.new
  File.foreach(filename) do |line|

         if line.include? 'uid'
              next unless line.match(/(?=uid).*?['"].*?['"](.*?)['"](.*?)[;"]/)
                field, value = line.split("=",2);
             ( configs[filename] = []  <<  value.strip.gsub("';", "").gsub("'",""))
               #( configs[filename][:uid] ||= [] ) <<  value.strip.gsub("';", "").gsub("'","") 
         end
   CSV.open("/tmp/data.csv", "wb", Options = {quote_char: "" }) {|csv| configs.each {|input| csv << input }}

现在我有最后一个问题,当我执行脚本时,我在输出中得到了这个问题

configuration_groupe-poult.mydomain.net.php,["group", "https://groupe-poult.mydomain.net", "group"]
configuration_kb-in.mydomain.net.php,["kbin", "https://kb-in.mydomain.net", "kauf"]

如何删除挂钩'[]和引号"?

我的猜测是,变量在您分配它们的块内是局部的。在脚本的开头添加以下内容:

uid = nil
url = nil
dbname = nil

相关内容

  • 没有找到相关文章

最新更新