Topic: Array of Hashes
Hi There,
man I did quite some searching, but I wasn't able to find the answer to my question. Maybe you can help me out?
Here's my code:
plist= {
"jboss" => {"pid" => ""},
"apache" => {"pid" => ""}
}
keys=plist.keys
begin
plist.each_key { |key|
pidlist=`ps -ef | grep #{key} | awk '{print $2}'`
pidlist.each do |pidname|
puts "pid to add " + pidname
# plist[key]["pid"] = plist[key]["pid"] + pidname.chomp.to_i
# plist[key]["pid"] << pidname.chomp
plist[key]["pid"] << pidname.chomp
end
}
puts plist.inspect
true
rescue Errno::ESRCH
false
endI'd like to create an hash of arrays like this:
{"jboss"=>{"pid"=>"3361", "4937", 5710"}, "apache"=>{"pid"=>"3365"}}
The best thing i could create was this:
{"jboss"=>{"pid"=>"336149375710"}, "apache"=>{"pid"=>"3365"}}
As you can see, all the values for "pid" are concatenated.. ![]()
What am I doing wrong?
Thank you in advance!