Robert Zielfelder wrote:
> 
> I have a bunch of subroutines defined in the script, but they don't need
> to
> be invoked unless the "@list_of_subs" contains the name of the sub.  I
> know that I could stick a bunch of if statements in there and make this
> work, but
> I am trying to be a little more efficient if I can.  Any insight would be
> appreciated.
> 

if the order of executing your subroutine is NOT important, use a hash:

#!/usr/bin/perl -w
use strict;

my %hash = ( sub1 => [\&sub1,1,2], sub2 => [\&sub2,3,4] );

while(my($name,$sub) = each %hash){
        my @subs = @{$sub};
        print "calling $name: ",$subs[0]->(@subs[1..$#subs]);
}

sub sub1{
        print "GETTING: @_\n";
}

sub sub2{
        print "GETTING: @_\n";
}

__END__

if the ordere of executing your subroutine is important, use an array:

#!/usr/bin/perl -w
use strict;

my @array = ( [\&sub1,1,2], [\&sub2,3,4] );

for(my $i = 0; $i < @array; $i++){
        my @subs = @{$array[$i]};
        $subs[0]->(@subs[1..$#subs]);
}

sub sub1{
        print "GETTING: @_\n";
}

sub sub2{
        print "GETTING: @_\n";
}

__END__

hope that help

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to