particle has asked for the wisdom of the Perl Monks concerning the following question:
while trying to override methods in Tie::StdHash, i've inadvertently screwed up STORE and FETCH. my print statement (last line) isn't printing the keys of %hash. i think it's in the My::TieHashTest methods, but i don't have my OO book handy. any ideas?
package My::TieHashTest; require Tie::Hash; @ISA= ( Tie::StdHash ); for( qw/ TIEHASH STORE FETCH FIRSTKEY NEXTKEY EXISTS CLEAR DELETE UNTIE DESTROY / ) { eval qq{ sub $_ { notify($_); shift->SUPER::$_ } } } sub notify { warn shift, $/ } package main; use strict; use warnings; tie my %hash => 'My::TieHashTest' or die; %hash= ( a=>1, b=>2, c=>3 ); $hash{d}= 4; print $_,$/ for keys %hash;
prints
> t-tiehash.pl TIEHASH CLEAR STORE STORE STORE STORE FIRSTKEY NEXTKEY DESTROY
~Particle *accelerates*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: tying hashes and SUPER
by dws (Chancellor) on Apr 16, 2003 at 20:01 UTC | |
by chromatic (Archbishop) on Apr 16, 2003 at 20:29 UTC | |
by particle (Vicar) on Apr 17, 2003 at 13:46 UTC | |
by tye (Sage) on Apr 16, 2003 at 20:34 UTC | |
by particle (Vicar) on Apr 16, 2003 at 20:25 UTC |