Err, why??

Try this

my %funcs=(
    "one"=> \&first,
    "two"=> \&second,
);

sub first {
        print "First";
}

sub second {
        print "Second";
}

&{$funcs{'one'}};


It's messy and relies on you naming you subroutines to match the static data
stored in %funcs. It will introduce more possible points of failure in the
code, make it harder to debug and maintain. Unless you've got a really good
reason why you need to do this, I'd suggest you don't.

John

-----Original Message-----
From: Pozsar Balazs [mailto:[EMAIL PROTECTED]]
Sent: 03 July 2001 17:33
To: [EMAIL PROTECTED]
Subject: pointers to subs?



Hi all,

I would want to use a hash to keep pointers to functions, and then call
them, but i'm stuck.
So:

I create:
my %funcs=(
    "one"=>           \&first,
    "two"=>           \&second);

Then how can I call 'first'? Obviously, using %funcs, i mean :).

thanks,
Balazs Pozsar.
-- 



--------------------------Confidentiality--------------------------.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.


Reply via email to