Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Defining a sub within a sub: OK?

by BrowserUk (Patriarch)
on Oct 14, 2009 at 22:45 UTC ( [id://801230]=note: print w/replies, xml ) Need Help??


in reply to Defining a sub within a sub: OK?

The main problem with nested subs, beyond the misleading apparent scoping of the innermost definition, is that Perl can only handle one level of closure, as (rather obliquely) indicated by the error message:

sub a{ my $x = 'fred'; sub b{ print $x } b(); }; a();; Variable "$x" will not stay shared at ... fred

By the time you leave the definition of sub a(), the variable $x no longer exists, but sub b(), is still callable.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-19 11:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found