You don't get a warning when undef is interpreted as the identity element of the operator. Or, in other words, when the following pattern isn't useless
For example:my $value; while (condition) # or for loop { $value <op>= something; }
ormy $sum; $sum += $_ for @nums;
And not setting the variable before the loop let's you tell if there were no valid lines at all, or if the only valid data was empty strings (or $sum will be undef rather than 0 if there are no numbers).my $valid; while (<DATA>) { chomp; next if /INVALID/; $valid .= $_; }
On the other hand you can use whatever values you want, this will never yield anything but 0:
This can only be a mistake.my $product; $product *= $_ for @nums;
So this would tend towards "this a right thing to do", but I couldn't find the documentation either.
Edit: that was full of typos. I wrote "under" for "undef", "is" for "if" and "identify" for "identity". I hope I got them all...
In reply to Re: Some "combined assignment operators" are exempt from "uninitialized value" warning. Is it documented anywhere?
by Eily
in thread Some "combined assignment operators" are exempt from "uninitialized value" warning. Is it documented anywhere?
by vr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |