perl - 无论创建范围如何,Perl 格式是否都绑定(bind)到文件句柄?

标签 perl format

我想在 $main_rpt_csv_fh 下面的示例 Perl 代码中定义一种格式,用于给定的文件句柄。

所以,我相信我的格式声明会像这样开始:

格式 main_rpt_csv_fh =

如果我尝试在子例程中创建它,使用 file_handle 的名称创建格式是否永久地将格式链接到文件句柄,或者文件句柄和格式是否必须在同一范围内?

这是我到目前为止编写的代码。

my $main_rpt_path = "/home/ics/work/rpts/interim/mtr_prebill.rpt";

my $main_rpt_fh = undef;


open $main_rpt_fh, "> ", 
   $main_rpt_path or die "$main_rpt_path: $!";

问这个问题的目的是让我的主要 Perl 代码保持整洁,在子例程中创建格式的想法会有所帮助。

例如,format 语句应该放在 fh 声明之前还是之后,以及 open 之前?

最后一个问题。格式是否是处理我想要的内容的最佳方式,即像旧的“greenbar”报告一样创建类似 spreadhseet(格式化)的数据?如果不是,首选方式是什么?

最佳答案

One final question. Are formats the best way to handle what I want, which is to create spreadhseet-like (formatted) data across like an old "greenbar" report? If not, what is the preferred way?

来自 Perl::Critic::Policy::Miscellanea::ProhibitFormats :

Formats are one of the oldest features of Perl. Unfortunately, they suffer from several limitations. Formats are static and cannot be easily defined at run time. Also, formats depend on several obscure global variables.

For more modern reporting tools, consider using one of the template frameworks like Template or try the Perl6::Form module.

关于perl - 无论创建范围如何,Perl 格式是否都绑定(bind)到文件句柄?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18162639/

相关文章:

perl - 我们可以在 Perl 中同时运行两个非嵌套循环吗?

java - 我的 Java 中的内联 Perl... Inline::Java::PerlInterpreter 不工作?

perl - Perl 单行代码末尾的 { 是什么意思?

javascript - 如何获取当前日期和时间,如下格式 3 :31 pm 7 July 2016

javax.el.E​​LException : Cannot convert 2015-12-03 18:50 of type class java. lang.String to class java.util.Date?

perl - 为什么新打开的句柄上的 FileHandle::getpos 返回空字符串而不是 0?

Perl SQLite DBI SELECT 绑定(bind)不起作用

python - 从 Python 中的除法中打印 %

python - 当我在 Odoo 中上传图像时,如何在对话框窗口中按图像格式进行过滤?

python - 使用 python 将 csv 单元格格式化为文本