根据本教程,这应该可以工作。
我已经在 5.14(和 5.16(中对此进行了测试,它似乎有效。这在 5.28 中不起作用。然而,似乎在perldoc perlform
它们仍然被记录为有效。
#!/usr/bin/perl
format EMPLOYEE =
===================================
@<<<<<<<<<<<<<<<<<<<<<< @<<
$name $age
@#####.##
$salary
===================================
.
select(STDOUT);
$~ = EMPLOYEE;
@n = ("Ali", "Raza", "Jaffer");
@a = (20,30, 40);
@s = (2000.00, 2500.00, 4000.000);
$i = 0;
foreach (@n) {
$name = $_;
$age = $a[$i];
$salary = $s[$i++];
write;
}
在 5.28,我得到
Scalar found where operator expected at ./test.pl line 6, near "$name $age"
(Missing operator before $age?)
syntax error at ./test.pl line 6, near "$name $age"
Execution of ./test.pl aborted due to compilation errors.
此功能在哪个版本上修改?这是 Perl 中记录在案的更改吗?
此处的删除是在无逗号变量列表中,这触发了早在 5.14 之前的警告。
在第6 行不推荐使用无逗号变量列表。
添加逗号使其在 5.26 中工作,
format EMPLOYEE =
===================================
@<<<<<<<<<<<<<<<<<<<<<< @<<
$name, $age
@#####.##
$salary
===================================
.