我想在 $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/