can induce the casual reader to think that the real semantic of the statement is that you have to assign to $a whatever the result you need from the application of reduce.my @result = reduce { $a += $b } @input;
The best counterexample that comes to my mind deals with an improper use of reduce, but bear with it. Suppose that the casual reader wants to count how many times the block is called. You could end up with:
but this obviously fails. So, it's probably better to write this from the beginning:my $counter = 0; my @result = reduce { $a += $b; $counter++ } @input;
and let the casual reader go read the documentation, understand that the last expression in the block is the new value given to $a at each iteration, and avoid headaches.my @result = reduce { $a + $b } @input;
Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf
In reply to Re^5: Bugs? Or only in my expectations?
by polettix
in thread Bugs? Or only in my expectations?
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |