Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^2: Call subroutine by reference ?

by sundialsvc4 (Abbot)
on May 31, 2013 at 10:48 UTC ( #1036222=note: print w/replies, xml ) Need Help??

in reply to Re: Call subroutine by reference ?
in thread Call subroutine by reference ?

Yes, and to clarify with-regard-to my previous post, there is no conflict between the two ideas ... they are quite-ordinarily used together, as Perl applications are quite-ordinarily built as systems of packages instead of monolithic and repetitive individual scripts.   If you use a package, the subs in them are (ordinarily ...) visible, both as subroutine_name and, if necessary, as package_name::subroutine_name.   You can build code-references freely, as shown, because everything comes-together in memory (just...) before execution of the whole thing begins.   The dispatch-table idea obviously is clearer and more-expandable than my if..elsif.. structure, which was merely used here for clarity.

n.b.:   In actual practice, the exists() function should be used to verify that the key being sought actually does exist in the table, before attempting the call.   e.g. die "horribly" unless exists($dispatch_table->{$key}); ... so that the program will react graciously, or at-least die on its own terms instead of puking with “can't use 'undef' as a code reference” or what-not.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1036222]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2018-06-19 05:36 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (111 votes). Check out past polls.