根据this tutorial,这应该起作用。
我已经在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
===================================
.