The keywords you are searching for here are 'partial function application' or 'currying'; both describe the practice of generating a new function with fewer arguments.
Continuing on LanX's answer, you can give the functions shorter names manually: my $light = $mysubs{'light'}; and then call them with $light->(10);
Anyway, if you want them installed to the symbol table, you can do this:
use strict; use warnings; my @sub_names = (qw/foo bar baz/); foreach my $name ( @sub_names ) { no strict 'refs'; *{__PACKAGE__ . "::" . $name} = sub { my ($parm) = @_; print "in $name (got $parm)\n"; } } foo(42); baz(10);
But be very careful about the content of @sub_names then. Standard cautions may apply, and using a hash is almost always better practice.
In reply to Re: a loop for creating subroutines?
by Anonymous Monk
in thread a loop for creating subroutines?
by mascip
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |