Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Ignoring the code you posted, aside from taking note of its indication that you might be asking specifically about sub references.....

Why sub references may be useful is really up to the imagination of the programmer, just as why while() {} may be useful. Sub refs are tools for you to put in your tool chest and use as they are found to be useful. In the type of work you do, you may find them to be seldom used. Others may find them extremely useful. A carpenter doesn't often use an oil filter wrench. A mechanic doesn't often use a nail gun. But farmer may use both in the course of his work-month.

If the hats you wear ever include using CGI::Carp, you might be exposed to using a sub-reference to set up your own error-handler. If you ever use File::Find, you use a subref for the "found" callback. If you program user interfaces, or parsers, you'll often use subrefs for event handlers and token handlers. Sub references allow a general solution to be applied to a specific situation.

References in general are a form of abstraction. An array, a hash, a subroutine, a simple scalar holding a value... they're abstraction layers that are very close to the data. When we need to apply a more generalized solution, we use references to those layers to distance ourselves from the data itself.

David Wheeler has been quoted as saying, "Any problem in computer science can be solved with another layer of indirection." References are one form of indirection. Of course the same Wheeler went on to qualify that with, "....Except for the problem of too many layers of indirection. (Thanks Wikipedia, for the quotes.)


Dave


In reply to Re: reference , advantages? by davido
in thread reference , advantages? by dbs

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-24 02:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found