Form a maintainable view, I would suggest you, to put things in OO style:
workflow.pm: package workflow; use strict; sub new { my $self = {}; $self->{TASKS} = []; bless $self; return $self; } sub add_task { my $self = shift; push @{$self->{TASKS}}, shift; } sub do_it { my $self = shift; my $item = shift; foreach my $task (@{$self->{TASKS}}) { &{$task}($item); } } 1; workflow_table.pm: package workflow_table; use workflow; use strict; sub new { my $self = {}; $self->{WORKFLOWS} = {}; bless $self; return $self; } sub add_task { my $self = shift; my $type = shift; my $task = shift; if (!defined($self->{WORKFLOWS}->{$type})) { $self->{WORKFLOWS}->{$type} = new workflow; } $self->{WORKFLOWS}->{$type}->add_task($task); } sub do_it { my $self = shift; my $type = shift; my $item = shift; $self->{WORKFLOWS}->{$type}->do_it($item); } 1; test.pl use workflow_table; use Data::Dumper; use strict; sub apple_wash {print "wash apple ".shift()."\n";} sub apple_core {print "core apple ".shift()."\n";} sub apple_pulp {print "pulp apple ".shift()."\n";} sub banana_bend {print "bend banana ".shift()."\n";} sub banana_hang {print "hang banana ".shift()."\n";} my $t = new workflow_table; $t->add_task("apple", \&apple_wash); $t->add_task("apple", \&apple_core); $t->add_task("apple", \&apple_pulp); $t->add_task("banana", \&banana_bend); $t->add_task("banana", \&banana_hang); $t->do_it("banana", "banana1"); $t->do_it("banana", "banana2"); $t->do_it("apple", "orange?");

In reply to Re: performance - loops, sub refs, symbol tables, and if/elses by pg
in thread performance - loops, sub refs, symbol tables, and if/elses by jaa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.