Tom Allison wrote:
> John W. Krahn wrote:
>>
>> my %subs = (
>>     f => sub {
>>         my $value = shift;
>>         print "$value\n";
>>         },
>>     g => sub {
>>         my $value = shift;
>>         print "\t$value\n";
>>         },
>>     );
>> my $var = shift;
>> $subs{ $var }( 'test' ) if exists $subs{ $var };
> 
> YUP!  That'll do it.  Thanks!
> 
> I think I've seen something like this before.
> That'll work.  Kind of strange though.
> I'm worried that my subroutines 'f' and 'g' might become 100's of lines
> long before I'm done.  Not very maintainable....

Well, you can define the subs anywhere and use references:

sub f {
    my $value = shift;
    print "$value\n";
    }

sub g {
    my $value = shift;
    print "\t$value\n";
    }

my %subs = (
    f => \&f,
    g => \&g,
    );
my $var = shift;
$subs{ $var }( 'test' ) if exists $subs{ $var };



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to