That's only true if g() has no side-effects and no performance penalty.
In reply to Re^4: scope of my $x in if statements by ikegami in thread scope of my $x in if statements by perl5ever