You're going about it the wrong way.  I assume that based on some previous
criteria, you need to perform a certain action, and you have that criteria
stored in the array: @list_of_subs

See if this works for you.

Create 1 sub, which we'll call MySub.
Pass it whatever is in the array, and have a bunch of if/elsif statements to
do different things based on the items in the array.

#Main Code
foreach $item(@list_of_whatever)  {  &MySub($item) }

#Our Sub
sub MySub
{
        if ($_ eq "something")
        {
                print "Doing this";
        }

        elsif ($_ eq "somethingElse")
        {
                print "Doing that";
        }

        else
        {
                die "DOA";
        }
}

-----Original Message-----
From: Zielfelder, Robert [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, September 24, 2002 1:44 PM
To: '[EMAIL PROTECTED]'
Subject: Using a variable name to invoke a subroutine


I have a script that uses an array to determine weather or not a subroutine
needs to be run or not.  I want to be able do a foreach on the array and
invoke the subroutine using the control variable.  The names of the
subroutines are the same as the items inside the array.  This is what I have
so far:

.....
foreach $sub (@list_of_subs) {
        &{$sub};  ##-- this is the part I am stuck on.  This doesn't work
}
.....

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.

Best Regards,

Rz


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

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

Reply via email to