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