RosettaCodeData/Task/Read-a-configuration-file/Sidef/read-a-configuration-file.sidef
2023-07-01 13:44:08 -04:00

27 lines
880 B
Text

var fullname = (var favouritefruit = "");
var needspeeling = (var seedsremoved = false);
var otherfamily = [];
ARGF.each { |line|
var(key, value) = line.strip.split(/\h+/, 2)...;
given(key) {
when (nil) { }
when (/^([#;]|\h*$)/) { }
when ("FULLNAME") { fullname = value }
when ("FAVOURITEFRUIT") { favouritefruit = value }
when ("NEEDSPEELING") { needspeeling = true }
when ("SEEDSREMOVED") { seedsremoved = true }
when ("OTHERFAMILY") { otherfamily = value.split(',')»strip»() }
default { say "#{key}: unknown key" }
}
}
say "fullname = #{fullname}";
say "favouritefruit = #{favouritefruit}";
say "needspeeling = #{needspeeling}";
say "seedsremoved = #{seedsremoved}";
otherfamily.each_kv {|i, name|
say "otherfamily(#{i+1}) = #{name}";
}