Tutorialspoint.com:Perl-格式:标量位于操作员期望的位置

时间:2019-10-05 02:21:04

标签: perl

根据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中记录的更改吗?

1 个答案:

答案 0 :(得分:3)

此处的删除位于无逗号变量列表中,该列表触发的警告早于5.14。

  

第6行弃用了无逗号变量列表。

添加逗号使其可以在5.26中使用

format EMPLOYEE =
===================================
@<<<<<<<<<<<<<<<<<<<<<< @<< 
$name, $age
@#####.##
$salary
===================================
.
相关问题