Last week when I read Apocalypse 4 I had terrible visions of what the elimination of "bare blocks" would mean for "static" variable declarations. I wasn't the only one confused, so I wrote a note to Larry and Damian asking that this notion be cleared up in the next exegesis.

This is the jist of the conversation relating to this topic. Damian: I hope you don't mind the reprinting of your mail, I'm sending a note to you asking forgiveness rather than permission in advance:

I asked:

We think (and maybe the Exegesis can clarify) that this means the elimination of two<super>*</super> succinct, obvious, and useful idioms. The declaration of C static-like variables ("compile-time" initializations):
{ my $foo=512; sub something { $foo++; } }
And other stuff. Damian's reply was:
That's now:
for 1 { my $foo=512; sub something { $foo++; } }
or:
INIT { my $foo=512; sub something { $foo++; } }
After I had whined:
Cluttering up these expressions with do {} and for 1 {} seems like syntatic nonsense and misdirection.
He said:
No, it's just a reflection of the fundamental change that a block is now *always* a closure (and hence a value). I actually think that the INIT {...} or even the BEGIN {...} approach is a much safer way to specify such things anyway, as it guarantees that the shared lexical (a lovely idiom, I agree) is initialized before any potential use of the subroutines that share it.
I hope this sheds a little light on the topic. I know it gave me a little more positive outlook on Exegesis 4.

<super>*</super>The other I asked about was shared lexicals between subs: { my $foo; sub bar{} sub baz{} }


In reply to Re: Static variables (and also Perl 6) by clintp
in thread Static variables (and also Perl 6) by tye

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.