presumably you are storing keys in %MyApp because you intend to check them at some other point in your package.
Actually, I do check them, but not at another point in the package, but at the same. Note the usage of ||=.
--
Ronald Fischer <ynnor@mm.st>
| [reply] [d/l] [select] |
Ah, I missed the side-effect of the function, sorry. In fairness, Perl has no way of knowing (as I should have from the name of the function, "log") that your function has a side-effect. If this function were to simply return a value, then the warning would make sense, because you would be storing a value and never using it. With the side-effect, though, everything becomes clear.
If you really want that syntax, then you should turn warnings off as others have suggested. Alternatively, you could use a syntax which mentions the variable twice. I don't know if the fact that I missed the meaning of your code is indicative of unclear syntax, or if it's just me being blind this morning.
| [reply] |
erl has no way of knowing (as I should have from the name of the function, "log") that your function has a side-effect.
This is correct, but if we use an operator like ||=, &&=, .= and so on, implies that at least at that statement, the value of the variable is read AND written, so one could argue that this means that the variable is used at least twice. This has nothing to do with whether or not the expression on the right-hand side has side effects. In other words:
$P::x ||= (f(),1);
produces a warning, while the equivalent
$P::x = $P::x || (f(),1);
does not.
--
Ronald Fischer <ynnor@mm.st>
| [reply] [d/l] [select] |