Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
maybe Symbol (even in the core distribution) could be of help here
I'll try incorporating that at some point to see how it fares, it will certainly save on the variable munging trickery.
Update: on second thoughts, this won't save variable name munging at all as I still have to create a lexical variable to assign to the glob etc etc If only I could create my own temporary lexical scopes to declare them in, hmmm ...
I believe that things get nasty if you nest subs two levels deep (or deeper) - that's one thing I miss from Pascal.
Nope, that's the beauty of lexical subs - you can nest to your hearts content!
use Sub::Lexical; ## can't nest package level subs sub foo { my $foovar = "in foo here\n"; my sub bar { my $barvar = "in bar here\n"; print "\$foovar = $foovar"; my sub baz { my $bazvar = "in baz here\n"; print "\$barvar = $barvar"; my sub quux { my $quuxvar = "in quux here\n"; print "\$bazvar = $bazvar"; my sub ooh_this_is_deep { my $ooh_this_is_deepvar = "in deep here\n"; print "\$otidv = $ooh_this_is_deepvar"; } ooh_this_is_deep(); } # ooh_this_is_deep falls outta scope here quux(); } # quux falls outta scope here baz(); } # baz falls outta scope here bar(); } # bar falls outta scope here foo(); __output__ $foovar = in foo here $barvar = in bar here $bazvar = in baz here $otidv = in deep here
The problem with nesting subs is explored here and this module fixes that issue to a degree by hiding by the nested subs as anonymous subs tied to lexicals variables, so you're not really nesting subs at all (but who's the wiser ? ;-)
HTH

_________
broquaint


In reply to Re: Symbol ? Re: Sub::Lexical by broquaint
in thread Sub::Lexical by broquaint

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (7)
    As of 2014-12-22 00:12 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (109 votes), past polls