On Tuesday, Sep 24, 2002, at 11:11 US/Pacific, nkuipers wrote:
>> foreach $sub (@list_of_subs) {
>> &{$sub}; ##-- this is the part I am stuck on. This doesn't work
>> }
>
> I don't know the answer to your question; I'm also interested in what
> others
> have to say. However, I have to w
Lots of good answers so far about using arrays, hashes etc, so
won't bother going there... look below to see an OOP that works
efficiently, using NAMEs rather than refs.
> -Original Message-
> From: Zielfelder, Robert
> [mailto:[EMAIL PROTECTED]]
> Sent: 24 September 2002 18:44
> To: '
Robert Zielfelder wrote:
>
> 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
On Tue, Sep 24, 2002 at 01:43:50PM -0400, Zielfelder, Robert wrote:
>
> foreach $sub (@list_of_subs) {
> &{$sub}; ##-- this is the part I am stuck on. This doesn't work
> }
>
This is called a soft reference, and soft references are generally a bad
idea. However, it should work.
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 mo
"%-s\n", (caller(0))[3];
}
Hopefully helpful.
Wags ;)
-Original Message-----
From: nkuipers [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, September 24, 2002 11:11
To: Zielfelder, Robert
Cc: [EMAIL PROTECTED]
Subject: RE: Using a variable name to invoke a subroutine
>foreach
here is two examples of that work for me
require "pl/require.pl";
$functiontocall ='RequireAll';
$functiontocall->();
--
-
my $alias = "home|SplitInput,LoadVariables,DirectUser,";
my ($name, $subs) = split(/\|/, $al
>foreach $sub (@list_of_subs) {
> &{$sub}; ##-- this is the part I am stuck on. This doesn't work
>}
I don't know the answer to your question; I'm also interested in what others
have to say. However, I have to wonder if Perl is looking at &{$sub} and
interpretting it as a command to ex
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 b
PROTECTED]'
Subject: RE: Using a variable name to invoke a subroutine
Instead of an array, you could change to a hash and use the
subroutine name as the key. Then if the key is defined, you execute
otherwise bypass.
Wags ;)
-Original Message-
From: Zielfelder, Robert [mailto:[EMA
Instead of an array, you could change to a hash and use the
subroutine name as the key. Then if the key is defined, you execute
otherwise bypass.
Wags ;)
-Original Message-
From: Zielfelder, Robert [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, September 24, 2002 10:44
To: '[EMAIL PR
11 matches
Mail list logo