in reply to Re: Annoying warnings...
in thread Annoying warnings...
Ugg — that's ugly, and quite obfuscated: it isn't apparent from glancing at that code exactly what it does or that it's written like that to avoid a warning
I disagree. That's a common idiomatic way of resolving the problem of false/undef in some expressions and I see it in lots of code.
The only problem with this strategy is that it sometimes gets used in places where non-undef false values like '0' shouldn't be ignored, which can lead to odd bugs. Not a problem in this instance.
$x && reftype $x eq 'HASH'
As already pointed out this breaks for true non-reference values.
In this particular instance I'd probably make it a bit more explicit the exact thing I'm looking for:
# I want a reference whose type is 'HASH' ref $x && reftype $x eq 'HASH';
|
|---|