I'm not sure just what you're asking for here, but maybe one of these will serve:
>perl -wMstrict -le "foreach my $origName (qw(foo bar baz)) { my $newName = qq{gen_$origName}; my $newCode = sub { print qq{generated $origName(@_)}; }; no strict 'refs'; *$newName = $newCode; } ;; gen_foo(1, 2, 3); gen_bar(4, 5, 6); gen_baz(7, 8, 9); ;; my $name = 'also_works'; eval qq{sub $name { print qq{this also works: \@_}; } }; also_works(9, 8, 7); " generated foo(1 2 3) generated bar(4 5 6) generated baz(7 8 9) this also works: 9 8 7
Update: This can be made a bit more concise (note the slightly tricky disambiguating semicolon in the
*{; ... } = sub { ... }
statement):
>perl -wMstrict -le "foreach my $origName (qw(foo bar)) { no strict 'refs'; *{; qq{gen_$origName} } = sub { print qq{generated $origName(@_)} } +; } ;; gen_foo(1, 2, 3); gen_bar(4, 5, 6); " generated foo(1 2 3) generated bar(4 5 6)
In reply to Re^3: Redefining function after fork
by AnomalousMonk
in thread Redefining function after fork
by gri6507
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |