我想這個問題可能會有些不那麼重要,但我一直在想,爲什麼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