如何使用模板工具包写出不同的输出文件

问题描述 投票:0回答:1

我是模板工具包的新手。我正在编写一个 perl 脚本并将哈希引用发送到模板模块中的进程对象。请找到参考哈希

 hash = {
          file 1 => 
                  { line 1 => 1,
                    line 2 => 2,
                    line 3 => 3,
                    line end => ok
                    }
          file 2 => 
                  { line 4 => 4,
                    line 5 => 5,
                    line 6 => 6,
                    line end => not ok
                    }
         }

Excepted output:
outpu1:
  1
  2
  3
  4
  5
  6
 ok
 outpu2:
  1
  2
  3
  4
  5
  6
  not ok

你能帮我解决逻辑吗,这样我就可以编写时间表和perl程序了。

目前我知道我们不能根据模板脚本中的条件编写不同的输出文件。您能否告诉我,在这种情况下,我是否可以将一些模式“文件 1”或“文件 2”与哈希一起发送到模板,以便我可以使用此模式并使用 2 个处理方法编写不同的输出

    $tt->process('template.tt',\%hash with file1 pattern,\$output1)  
    $tt->process('template.tt',\%hash with file2 pattern,\$output2) 

抱歉,如果问题不恰当。尝试理解逻辑而不是编程来实现这个场景。

perl template-toolkit
1个回答
0
投票

目前我知道我们不能根据模板脚本中的条件编写不同的输出文件。

重定向过滤器不同意。

© www.soinside.com 2019 - 2024. All rights reserved.