Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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.


Comment on Re^2: Call subroutine by reference ?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1036222]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2015-07-04 09:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (59 votes), past polls