help with dispatch array

help with dispatch array

am 10.06.2009 01:37:12 von Barry Brevik

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.
=20
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.
=20
Am I dreaming, or is this possible?
=20
Barry Brevik
=20

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



charset=3Dus-ascii">


I =
am running=20
Active Perl 5.8.8 on Windows.

size=3D2> 

I'm =
coding an app=20
right now where it would be advantageous to be able to look up a text =
string in=20
an array (or hash) and be able to branch to a subroutine that is somehow =

associated with that string.

size=3D2> 

Am =
I dreaming, or=20
is this possible?

size=3D2> 

size=3D2>Barry=20
Brevik

 


------_=_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@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0964598361==--

Re: help with dispatch array

am 10.06.2009 01:43:32 von Michael Ellery

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@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: help with dispatch array

am 10.06.2009 08:15:49 von Williamawalters

--===============2072573069==
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@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: @_} },
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


**************
Download the AOL Classifieds Toolbar for local deals at your
fingertips.
(http://toolbar.aol.com/aolclassifieds/download.html?ncid=em lcntusdown00000004)

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

hi barry an=
d mike --   



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



> So, something like:

>

> my %functionTable =3D (

>   'string_1' =3D> sub {

>    },

>   'string_2' =3D> 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); &nbs=
p;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 =3D (

  string_1 =3D> sub { print qq{one: @_} },

  string_2 =3D> 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   



**************
Download the AOL Classifieds Toolbar=
for local deals at your fingertips. (http://toolbar.aol.com/aolclassified=
s/download.html?ncid=3Demlcntusdown00000004)

--part1_c66.54675c5c.3760a995_boundary--

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

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============2072573069==--