ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> activeperl
activeperl
Re: help with dispatch array
by Williamawalters other posts by this author
Jun 9 2009 11:16PM messages near this date
Re: help with dispatch array | s/ / /; - doing harm ?
hi barry and mike --   

In a message dated 6/9/2009 6:44:02 PM Eastern Standard Time, 
mikee@[...].com writes:

>  So, something like:
>  
>  my %functionTable = (
>    'string_1' => sub {
>     },
>    'string_2' => sub {
>     },
>  );
>  
>  invocation via:
>  
>  &$functionTable{'string_1'}(ARGLIST);
>  
>  ..is that what you had in mind?
>  
>  -Mike
>  
>  Barry Brevik wrote:
>  > I am running Active Perl 5.8.8 on Windows.
>  >  
>  > I'm coding an app right now where it would be advantageous to be able to
>  > look up a text string in an array (or hash) and be able to branch to a
>  > subroutine that is somehow associated with that string.
>  >  
>  > Am I dreaming, or is this possible?
>  >  
>  > Barry Brevik

in the expression  &$functionTable{'string_1'}(ARGLIST);  the & operator 
binds more tightly with  $functionTable  as a scalar than as a hash 
access.  try the syntax below, or better yet use the  ->   dereference 
operator.   

perl -wMstrict -le
"my %functionTable = (
   string_1 =>  sub { print qq{one: @_} },
   string_2 =>  sub { print qq{two: @_} },
   );
 &{ $functionTable{string_1} }(qw(a b c));
 $functionTable{string_2}-> (qw(x y z));"
one: a b c
two: x y z

hth -- bill walters   
<BR> <BR>**************<BR>Download the AOL Classifieds Toolbar for local deals at your 
fingertips. 
(http://toolbar.aol.com/aolclassifieds/download.html?ncid=emlcntusdown00000004)</HTML> 
Thread:
Barry Brevik
Michael Ellery
Williamawalters

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved