Hi Harry,

thanks for replying inline (bottom posting).

On Thursday 06 May 2010 16:19:32 Harry Putnam wrote:
> Shlomi Fish <shlo...@iglu.org.il> writes:
> 
> 
> [...]
> 
> > sub dispatch
> > {
> > 
> >     my ($method, @rest_of_args) = @_;
> 
> Not sure what $method is supposed to be doing.
> 

Sorry, I'm usually used to doing symbolic dispatches using object instances 
and dynamic method lookups. So I can do something like:


<<<
sub _handle_case
{
        my $self = shift;
        my $case = shift;
        my $args = shift;

        my $method = "_handle_case_of_${case}";

        return $self->$method($args);
}
>>>

And then have something like _handle_case_of_zebra() , 
_handle_case_of_elephant(), _handle_case_of_tiger(), etc.

Naturally, in this case $method should be better named as "$case" or "$which" 
or something.

> >     my %dispatch =
> >     (
> >     
> >             'N' => sub { return N_func(@rest_of_args); },
> >             'L' => sub { return L_func(@rest_of_args); },
> >             .
> >             .
> >             .
> >     
> >     );
> >     
> >     return $dispatch{$method}->();
> > 
> > }
> 
> Where is $method being sent?

It's sent to the dispatch table - "$dispatch{$method}" looks up a subroutine 
reference and the ->() executes it with an empty argument.

> 
> What I'm trying to do:
> 
> Iterating through a list of lists using a dispatch table to
>  `dispatch' one member of each list fed to it, or sometimes the whole
>  list needs to be acted on.

Are you iterating through an array of arrays? How do you determine which 
handler to use for each array? Are they all treated the same regardless of 
their context within the larger array?

Regards,

        Shlomi Fish

> 
> I'm trying to work up a good example but having to experiment a lot to
> get even that done.

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Original Riddles - http://www.shlomifish.org/puzzles/

God considered inflicting XSLT as the tenth plague of Egypt, but then
decided against it because he thought it would be too evil.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to