Thread Hashreferenz auf Gültigkeit prüfen (9 answers)
Opened by Duff at 2008-08-01 13:58

pq
 2008-08-01 14:19
#112982 #112982
User since
2003-08-04
12208 Artikel
Admin1
[Homepage]
user image
renee+2008-08-01 12:04:45--
Kommt darauf an, wie genau Du das prüfen willst...

Code (perl): (dl )
1
2
3
if( $hash_ref and ref( $hash_ref ) and ref( $hash_ref ) eq 'HASH' and keys %$hash_ref ){
    #...
}

da ist ein grosser teil unnötig.
Code (perl): (dl )
if (ref $hash eq 'HASH' and keys %$hash) {

ref() liefert nämlich bei undef oder keiner ref einfach den leeren string.
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem

View full thread Hashreferenz auf Gültigkeit prüfen