Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Defining a sub within a sub: OK?

by AnomalousMonk (Archbishop)
on Oct 14, 2009 at 21:59 UTC ( [id://801223]=note: print w/replies, xml ) Need Help??


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

Your code does not define a sub within a sub, but a sub within a code block.
Actually, the sub  level1 is defined (and called) within an explicit scope, not within a code block.

Since there are no lexicals also defined within the scope and referred to by the subroutine, the scope has no effect; subroutines themselves are globally scoped.

Replies are listed 'Best First'.
Re^3: Defining a sub within a sub: OK?
by jwkrahn (Abbot) on Oct 14, 2009 at 22:12 UTC

    Subroutine names are package variables and therefore not "globally scoped".    Only certain Perl variables fit the definition of "globally scoped".

    the sub level1 is defined within an explicit scope, not within a code block.

    Basic BLOCKs

      What I meant by 'globally scoped' was 'accessible from any point of execution within the program', and package variables do fit this definition.

      I agree with jwkrahn's point about the 'code block' (as defined in the referenced discussion of blocks). What I thought was meant was a 'code block' of the sort associated with sort and other such built-ins, e.g.,
          my @sorted = sort { $a <=> $b } @unsorted;

      (Hang on, I may be experiencing a 'lobe block' ... )

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-20 01:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found