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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Incidently, why do you want a sub sub? Is it so your sub can access private variables, or so your sub can use a routine name that may already be in use, or what? Just curious.

One of the nice things about block-local sub definitions is that they stay local to that block. In other words, you only have to understand that sub in the context of the block it's declared in, which makes a lot of sense when that's the only place it gets used.

For example, I have some C code that reads a TARGA image. Obviously, I don't want to do everything in a single function, so I break it up into one user-visible routine (read_tga_file) and two helper routines (read_tga_header and read_tga_image). The two helpers only ever get called within read_tga_file, so why should they be part of tga.o's global symbol space? If I could declare the helpers within read_tga_file's symbol space, anyone reading the file would know that they only get used there. That's a win, especially when the helper functions are a bit less obviously specialized. Lexical function declarations let you encode some of your assumptions in source code.

This idea of "declare stuff in the smallest enclosing lexical block" is ubiquitous in the functional-programming world. As usual, Perl lets you do it with minimal fuss.

F o x t r o t U n i f o r m
Found a typo in this node? /msg me
% man 3 strfry

In reply to Re^4: Is it possible to create a sub exclusive to a sub? by FoxtrotUniform
in thread Is it possible to create a sub exclusive to a sub? by punkish

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 or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2022-09-27 18:24 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (123 votes). Check out past polls.