sub TIEHASH { my $pkg = shift ; bless { VALID => { map {$_, 1} qw( bsize ffactor nelem cachesize hash lorder) }, GOT => {} }, $pkg ; } #### #!/usr/bin/perl -- use strict; use warnings; Main(@ARGV); exit(0); sub Main { Waha('NewHash'); Waha('OneHash'); } sub Waha { my $c = shift; my $obj = tie my (%foo), $c or die $!; printf '(%s) $obj=(%s) tied(%%foo)=(%s)' . "\n", $c, $obj, tied(%foo) || 'undef'; } ## end sub Waha BEGIN { package NewHash; sub TIEHASH { my $obj = bless {}, shift; return $obj; } package OneHash; sub TIEHASH { "$_[0] is broken" } } ## end BEGIN __END__ (NewHash) $obj=(NewHash=HASH(0x3d8bbc)) tied(%foo)=(NewHash=HASH(0x3d8bbc)) (OneHash) $obj=(OneHash is broken) tied(%foo)=(undef) (NewHash) $obj=(NewHash=HASH(0x225368)) tied(%foo)=(NewHash=HASH(0x225368)) (OneHash) $obj=(OneHash is broken) tied(%foo)=(undef)