http://qs321.pair.com?node_id=162577

CharlesClarkson has asked for the wisdom of the Perl Monks concerning the following question:

I perused perlmonks and google in search of a dispatch table. The examples I found didn't pass arguments with the named subroutines. I think I have it solved, but would like confirmtion.

#!/usr/bin/perl -w use strict; $|++; my $fruit = [ qw|apple orange pear| ]; my $dispatch = { add => sub { return add_entry( $fruit ) }, }; print scalar localtime, "\n"; sleep 1; print &{ $dispatch->{add} }, " <-- from sub \n";; sleep 1; print scalar localtime, "\n"; sub add_entry{ print scalar localtime, " <-- in sub \n"; sleep 1; return scalar localtime; } __END__ produces: Sat Apr 27 19:00:21 2002 Sat Apr 27 19:00:22 2002 <-- in sub Sat Apr 27 19:00:23 2002 <-- from sub Sat Apr 27 19:00:24 2002
    Two questions:
  1. Is the test valid?
  2. Am I missing some pitfall that will bite me later?

Thank You,
Charles K. Clarkson
Clarkson Energy Homes, Inc.