package myHash; sub new { bless {}, shift } sub AUTOLOAD { # next two lines just to see what's happening... print '@_ = ('.join(', ',map{"'$_'"}@_), ")\n"; print "\$AUTOLOAD = $AUTOLOAD\n"; my ($self,$value) = @_; (my $key = $AUTOLOAD) =~ s/.*:://; $self->{$key} = $value if $value; $self->{$key}; } 1; #### #!/usr/bin/perl use myHash; $thingy = myHash->new(foo => 'bar'); print $thingy->foo,"\n"; print $thingy->foo('baz'),"\n"; print $thingy->age('ageless'),"\n"; __END__ #output: @_ = ('myHash=HASH(0x8166c28)') $AUTOLOAD = myHash::foo @_ = ('myHash=HASH(0x8166c28)', 'baz') $AUTOLOAD = myHash::foo baz @_ = ('myHash=HASH(0x8166c28)', 'ageless') $AUTOLOAD = myHash::age ageless @_ = ('myHash=HASH(0x8166c28)') $AUTOLOAD = myHash::DESTROY