in reply to Weird eval behavior...

This works fine for me:

@attribute_list = qw( foo bar baz ); $package="Zoikes"; for (@attribute_list) { my $sub = qq{package $package; sub get$_ { \$_[0]->get("$_") } }; eval $sub; warn "Problem with $_: $@\n" if $@; } { package Zoikes; sub get { print "Zoikes::get( $_[1] )\n" } } $z = bless { }, "Zoikes"; $z->getfoo; $z->getbar; $z->getbaz; exit 0;

Also consider checking out Class::MethodMaker to avoid reinventing too many wheels.

Replies are listed 'Best First'.
Re: Re: Weird eval behavior...
by dragonchild (Archbishop) on Oct 09, 2001 at 21:47 UTC
    That works. I have no idea what's different, other than the double-quoting of the $_, which shouldn't make a different ... should it??

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

      Well, that (""'ing around $_) makes it pass a string rather than a bareword.