if( $r and UNIVERSAL::isa($r,'HASH') and %$r ) { ... }