in reply to difference between 'if (condition) { expression;}' and 'expression if (condition)'

This is easy: The two bracets make up an extra namespace, in which $var is "declared" in the first examples. But the print statement is out of that namespace, so $var is not known there.
  • Comment on Re: difference between 'if (condition) { expression;}' and 'expression if (condition)'

Replies are listed 'Best First'.
Re^2: difference between 'if (condition) { expression;}' and 'expression if (condition)'
by revdiablo (Prior) on Mar 22, 2006 at 21:56 UTC
    The two bracets make up an extra namespace

    I would avoid calling this a "namespace". The brackets in this example are creating a lexical scope. When someone says "namespace" in Perl, they almost always mean a package.