Edit: Because I couldn't find the documentation I expected the return value of an if block to be undefined behaviour, but Haukex's answer makes much more sense. You can ignore the rest of this post (except maybe the bit about Deparse, which actually confirms Haukex's version).

You used an if in a do block. So I'll give you an answer for a for loop, maybe in a function ;-)
perlsub:
If the last statement is a loop control structure like a foreach or a while, the returned value is unspecified

perlsyn:
Perceptive Perl hackers may have noticed that a for loop has a return value, and that this value can be captured by wrapping the loop in a do block. The reward for this discovery is this cautionary advice: The return value of a for loop is unspecified and may change without notice. Do not rely on it.

I quote those because I couldn't even find the relevant documentation for other kind of blocks. As far as I can tell it's not just unspecified, it's undocumented. The reason is quite clearer though, some freedom is left for perl to try and optimize your statement. So if (0) {SOMETHING} might be removed entirely, or replaced by a no-op. The condition in if (1) might be removed because the block is always executed. Actually this is confirmed by deparsing the code (perl -MO=Deparse yourfile.pl):

BEGIN { $/ = "\n"; $\ = "\n"; } use strict; use warnings; my $uninitialized; print do { $uninitialized }; print do { () }; print do { do { () } }; print do { 0 }; print '----------'; print scalar do { $uninitialized }; print scalar do { () }; print scalar do { do { () } }; print scalar do { 0 };
You can see that the if (1) {} is turned into do {}, and the if (0) is turned into 0. But this is not reliable behaviour, that's just a side effect of perl trying to replace some statements by the best equivalent it could find.


In reply to Re: printing unitialized value of the 'do BLOCK' by Eily
in thread printing unitialized value of the 'do BLOCK' by rsFalse

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.