Since I don't really know what you're doing, I've made minimal changes to your OPed code (but even so, please pay close attention to the Anonymonk's wise advice here and here). Try something like this:

c:\@Work\Perl>perl -wMstrict -le "{ package ProcessData; ;; use warnings; use strict; use Carp qw(croak); ;; sub new { my ($pkg) = $_[0]; bless { _dispatch_table => {}, }, $pkg; } ;; sub add_subroutine { if($_[1] && $_[2]) { if(ref($_[2]) eq \"CODE\") { ${$_[0]->{_dispatch_table}}{$_[1]} = $_[2]; } else { croak qq{non-CODE reference '$_[2]' passed to add_subroutine( +)}; } } else { croak \"Insufficient arguments passed to add_subroutine(). \"; } } ;; sub process_data { my $self = shift; ;; die qq{no dispatch given} unless @_; my $dispatch = shift; die qq{unknown dispatch '$dispatch'} unless exists $self->{_dispatch_table}{$dispatch}; ;; return $self->{_dispatch_table}{$dispatch}->(@_); } ;; sub process_locations { my $self = shift; return $self->process_data('locations', @_); } ;; } ;; use warnings; use strict; ;; my $pd = ProcessData->new(); ;; $pd->add_subroutine('locations', \&get_locations); ;; $pd->process_locations(qw(here there everywhere)); ;; sub get_locations { print qq{we got stuff: @_} } " we got stuff: here there everywhere


Give a man a fish:  <%-{-{-{-<


In reply to Re: Is it possible to call a package::main subroutine from a module? by AnomalousMonk
in thread Is it possible to call a package::main subroutine from a module? by TorontoJim

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.