我想这个问题可能会有些不那么重要,但我一直在想,为什么Perl中没有低优先级定义或运算符。我想这是有原因的,因为perlop明确提到了这个事实。在那里我会觉得它有用为什么在Perl中没有相当于//的低优先级?
一个实例就是在这样的子程序:
sub input_many_data {
my $x = <> // return;
do_some_processing_with($x);
my $y = <> // return;
do_some_processing_with($y);
return ($x, $y);
}
while (1) {
my ($x, $y) = &input_many_data or last;
do_something_with($x, $y);
}
它确实有$x = (<> // return)
工作,但目的会更明显,并且代码更易读且不易出错,像($x = <>) dor return
。
我也总是希望这样的操作存在。原因可能是p5p的个人构成。 – choroba