if ( defined $r && ref $r && ref $r eq 'HASH' && keys %$r ) { ... }
There's no need to write it like that. 'ref' never returns an undefined variable. You may write this as:
if (ref($r || "") eq 'HASH' && keys %$r) { ... }
Or, after turning off the appropriate warning:
if (ref $r eq 'HASH' && keys %$r) { ... }
which isn't too bad.

Note that it won't enter the block if $r is a blessed hash, but that I consider a feature. (Otherwise, replace ref with Scalar::Util::reftype).

In reply to Re^2: disadvantages of perl by JavaFan
in thread disadvantages of perl by perldesire

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":