我有以下常规脚本:
#!/usr/bin/env groovy
def files = [
'file-1.bat' :
[
'content-1-1',
'content-1-2',
'content-1-3'
],
'file-1' :
[
'content-unix-1-1',
'content-unix-1-2',
'content-unix-1-3',
],
'file-2.bat' :
[
'content-2-1',
'content-2-2',
'content-2-3'
],
'file-2' :
[
'content-unix-2-1',
'content-unix-2-2',
'content-unix-2-3',
],
]
files.each {
file_key, file_value -> println file_key;
file_value.each {
file_content -> println "\t"+file_content;
files[ file_key ] = [file_content : true];
}
}
println ' Upgraded content';
files.each {
file_key, file_value -> println file_key;
file_value.each {
file_content -> println "\t"+file_content;
}
}
以下几行导致我的问题:
files[ file_key ] = [file_content : true];
我想要做的是为地图中的每个条目创建键:值对的真实部分......我知道我没有以那种方式定义列表......我试图增强使用 files[file_key].put(key, value) 映射;但这不起作用...也许我在想一个完全错误的方向...该构造的背景是在文件(file-1.bat、file-1 等)中,我将检查是否存在以地图形式给出的内容
'file-1.bat' : [
'content-1-1',
'content-1-2',
'content-1-3'
],
我可以执行以下操作:
'file-1.bat' : [
'content-1-1' : false,
'content-1-2' : false,
'content-1-3' : false,
],
但这正是我想要避免的。