help with dispatch array

This is a multi-part message in MIME format.

--===============0964598361==
Content-class: urn:content-classes:message
Content-Type: multipart/alternative;
boundary="----_=_NextPart_001_01C9E95B.2515C147"

This is a multi-part message in MIME format.

------_=_NextPart_001_01C9E95B.2515C147
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

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


------_=_NextPart_001_01C9E95B.2515C147
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dus-ascii">
<META content=3D"MSHTML 6.00.6000.16825" name=3DGENERATOR></HEAD>
<BODY>
<DIV><SPAN class=3D027463323-09062009><FONT color=3D#000080 size=3D2>I =
am running
Active Perl 5.8.8 on Windows.</FONT></SPAN></DIV>
<DIV><SPAN class=3D027463323-09062009><FONT color=3D#000080
size=3D2></FONT></SPAN> </DIV>
<DIV><SPAN class=3D027463323-09062009><FONT color=3D#000080 size=3D2>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.</FONT></SPAN></DIV>
<DIV><SPAN class=3D027463323-09062009><FONT color=3D#000080
size=3D2></FONT></SPAN> </DIV>
<DIV><SPAN class=3D027463323-09062009><FONT color=3D#000080 size=3D2>Am =
I dreaming, or
is this possible?</FONT></SPAN></DIV>
<DIV><SPAN class=3D027463323-09062009><FONT color=3D#000080
size=3D2></FONT></SPAN> </DIV>
<DIV><SPAN class=3D027463323-09062009><FONT color=3D#000080 =
size=3D2>Barry
Brevik</FONT></SPAN></DIV>
<DIV><SPAN class=3D027463323-09062009></SPAN> </DIV></BODY></HTML>

------_=_NextPart_001_01C9E95B.2515C147--

--===============0964598361==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0964598361==--
Barry Brevik [ Mi, 10 Juni 2009 01:37 ] [ ID #2004636 ]

Re: help with dispatch array

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
>
>
>
> ------------------------------------------------------------ ------------
>
> _______________________________________________
> ActivePerl mailing list
> ActivePerl [at] listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Michael Ellery [ Mi, 10 Juni 2009 01:43 ] [ ID #2004637 ]

Re: help with dispatch array

--============== 72573069==
Content-Type: multipart/alternative;
boundary="part1_c66.54675c5c.3760a995_boundary"


--part1_c66.54675c5c.3760a995_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

hi barry and mike --

In a message dated 6/9/2009 6:44:02 PM Eastern Standard Time,
mikee [at] s2technologies.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: [at] _} },
string_2 => sub { print qq{two: [at] _} },
);
&{ $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=em lcntusdown00000004)</HTML>

--part1_c66.54675c5c.3760a995_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable

<HTML><FONT FACE=3Darial,helvetica><FONT SIZE=3D2 PTSIZE=3D10>hi barry an=
d mike --   
<BR>
<BR>In a message dated 6/9/2009 6:44:02 PM Eastern Standard Time, mikee [at] s2=
technologies.com writes:
<BR>
<BR>> So, something like:
<BR>>
<BR>> my %functionTable =3D (
<BR>>   'string_1' =3D> sub {
<BR>>    },
<BR>>   'string_2' =3D> sub {
<BR>>    },
<BR>> );
<BR>>
<BR>> invocation via:
<BR>>
<BR>> &$functionTable{'string_1'}(ARGLIST);
<BR>>
<BR>> ..is that what you had in mind?
<BR>>
<BR>> -Mike
<BR>>
<BR>> Barry Brevik wrote:
<BR>> > I am running Active Perl 5.8.8 on Windows.
<BR>> >  
<BR>> > I'm coding an app right now where it would be advantageous=
to be able to
<BR>> > look up a text string in an array (or hash) and be able to=
branch to a
<BR>> > subroutine that is somehow associated with that string.
<BR>> >  
<BR>> > Am I dreaming, or is this possible?
<BR>> >  
<BR>> > Barry Brevik
<BR>
<BR>in the expression  &$functionTable{'string_1'}(ARGLIST); &nbs=
p;the & operator
<BR>binds more tightly with  $functionTable  as a scalar than as=
a hash
<BR>access.  try the syntax below, or better yet use the  ->=
 dereference
<BR>operator.   
<BR>
<BR>perl -wMstrict -le
<BR>"my %functionTable =3D (
<BR>   string_1 =3D> sub { print qq{one: [at] _} },
<BR>   string_2 =3D> sub { print qq{two: [at] _} },
<BR>   );
<BR> &{ $functionTable{string_1} }(qw(a b c));
<BR> $functionTable{string_2}->(qw(x y z));"
<BR>one: a b c
<BR>two: x y z
<BR>
<BR>hth -- bill walters   
<BR></FONT><BR><BR>**************<BR>Download the AOL Classifieds Toolbar=
for local deals at your fingertips. (http://toolbar.aol.com/aolclassified=
s/download.html?ncid=3Demlcntusdown00000004)</HTML>

--part1_c66.54675c5c.3760a995_boundary--

--============== 72573069==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--============== 72573069==--
Williamawalters [ Mi, 10 Juni 2009 08:15 ] [ ID #2004638 ]
Perl » gmane.comp.lang.perl.active-perl » help with dispatch array

Vorheriges Thema: Installed 5.10, need to re-install packages?
Nächstes Thema: s/ / /; - doing harm ?