On Thu, 10 Jul 2008, David Kaufman wrote: > > my $foo = 'bar' if $baz; > > I wish it would still DWIM, and by that I mean the compiler should detect > my declaration + assignment + conditional and rewrite it for me as what I > meant which was simply: > > my $foo = $baz ? 'bar' : undef; >
I disagree. In the first, you are telling perl that you want to create a symbol if a certain condition is true. Maybe under some conditions you don't want to create that symbol. Consider the same logic applied to hash assignment: my %foo; $foo{bar} = 'baz' if $biz; frob() if exists $foo{bar}; You would expect that $foo{bar} would not exist if $biz was false. But under your recommendation, it would exist. This is not the way it should behave. Mark