John W. Krahn wrote:
Tom Allison wrote:

#!/usr/bin/perl
use strict;
use warnings;
sub f {
       my $value = shift;
       print $value,"\n";
}
sub g {
       my $value = shift;
       print "\t",$value,"\n";
}
my $var = shift;
my $code = \&$var;
&$code("test");
=============================
I got this working well enough but it's not quite what I'm looking for.
I hope I'm close.

I need to make sure that the value in $var is a function that exists...
Is there some method to do that which isn't going to require a LOT of
overhead.  I was thinking this might be a fast solution (unproven).



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 };



John

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....

--
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