"Dan Sugalski" <dan / sidhe.org> wrote in .... > >Write how you do this in Perl without using eval. You can do it with eval > >in Ruby, but the original posters would like something that uses not eval > >(not sure why). > > Sure. > > If your methods (or subs, whatever) can be synthesized at runtime by > just changing data and building a closure, you can do something like: > > sub make_getter { > my $element = $_[0]; > *{"__PACKAGE__::get_$element"} = sub {return $_[0]->{$element}}; > } Someone correct me if am wrong but that seems to be Perl's version of Ruby's Module#define_method in 1.7.? .... /Christoph P.s The original Poster mentions that he dismissed using Structs because of problems with Marshalling - in which case he should stay away from Ruby's singletons unless he is willing to provide custom instance (or singleton) Record#_dump method(s) and a custom Record::_load class method.