Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: Is it possible to create a sub exclusive to a sub?

by TedPride (Priest)
on Sep 19, 2004 at 01:02 UTC ( #392078=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Is it possible to create a sub exclusive to a sub?
in thread Is it possible to create a sub exclusive to a sub?

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.


Comment on Re^3: Is it possible to create a sub exclusive to a sub?
Re^4: Is it possible to create a sub exclusive to a sub?
by punkish (Priest) on Sep 19, 2004 at 01:05 UTC
    Incidently, why do you want a sub sub?

    simply to cut down on line clutter.

    The subsub has a lot of lines that otherwise would be repeated. Now they don't have to be... I have had run into this a lot in the past, but have never figured it could be possible. Now I know a better way of doing what I have been doing.

Re^4: Is it possible to create a sub exclusive to a sub?
by FoxtrotUniform (Prior) on Sep 19, 2004 at 01:59 UTC
    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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (12)
As of 2014-09-16 22:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (51 votes), past polls