1. ($var and (my $foo = 'blah'));The second part of this statement will never be executed if $var is undefined. The 'and' is short-circuited, so the second part of the statement (the re-initialization of $foo) is optimized away never evaluated.
  2. You are right. Poor use of the term "symbol table" on my part, since $foo is a lexical variable. I just got typing too fast ;-) However, I never meant to say that $foo was available outside of the block. What I meant was that it was initialized on the first call to mysub and retains the original value within that block since it is never re-initialized, just like using a sub to create a static variable as in perlfaq7. You can also get the same result (a static variable) by using my $i = 0 if 0;
On a side note, does anyone know of links/books/perldoc that I can look at which document this "feature"?
I think this feature should be spelled 'b-u-g'

And about strict not complaining, I was just plain wrong.

Update: Changed "optimized away" - Aristotle++.


In reply to Re: Re: Re: Re: Re: static-like persistence of my variable due to trailing conditional by jsprat
in thread static-like persistence of my variable due to trailing conditional by meonkeys

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.